Taxicab numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 3,572: | Line 3,572: | ||
25 402597 => 56³ + 61³, 42³ + 69³ |
25 402597 => 56³ + 61³, 42³ + 69³ |
||
ok |
ok |
||
</pre> |
|||
=={{header|RPL}}== |
|||
A priority queue allows to get the first 25th taxicab numbers without being killed by the emulator timedog. |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! Code |
|||
! Comments |
|||
|- |
|||
| |
|||
≪ |
|||
{} 1 PQueue SIZE FOR j |
|||
IF OVER j ≠ THEN PQueue j GET 1 →LIST + END |
|||
NEXT |
|||
'PQueue' STO DROP |
|||
≫ 'PQPop' STO |
|||
≪ |
|||
0 {} → idx item |
|||
≪ 0 1 PQueue SIZE FOR j |
|||
PQueue j GET 1 GET |
|||
IF DUP2 < |
|||
THEN SWAP PQueue j GET 'item' STO j 'idx' STO |
|||
END DROP |
|||
NEXT |
|||
DROP idx item |
|||
≫ ≫ 'PQMax' STO |
|||
≪ → pos |
|||
1 CF PQueue SIZE WHILE DUP 1 FC? AND REPEAT |
|||
IF PQueue OVER GET pos GET 3 PICK == THEN 1 SF END |
|||
1 - |
|||
END |
|||
DROP2 1 FS? |
|||
≫ ≫ 'PQin?' STO |
|||
≪ OVER 3 ^ OVER 3 ^ + ROT ROT |
|||
3 →LIST 1 →LIST PQueue + 'PQueue' STO |
|||
≫ 'PQAdd' STO |
|||
≪ → item |
|||
≪ IF item 1 GET LastItem 1 GET == THEN |
|||
{} item 1 GET + item 2 GET item 3 GET R→C + |
|||
LastItem 2 GET LastItem 3 GET R→C + 1 →LIST |
|||
TaxiNums + 'TaxiNums' STO |
|||
END |
|||
item 'LastItem' STO |
|||
≫ ≫ 'StoreIfTwice' STO |
|||
≪ WHILE PQueue SIZE REPEAT |
|||
PQMax DUP StoreIfTwice LIST→ DROP 4 ROLL PQPop → r c |
|||
≪ IF r 1 > |
|||
THEN IF r 1 - 2 PQin? NOT |
|||
THEN r 1 - c PQAdd END END |
|||
IF c 1 > c r > AND |
|||
THEN IF c 1 - 3 PQin? NOT |
|||
THEN r c 1 - PQAdd END |
|||
END |
|||
DROP |
|||
≫ |
|||
END |
|||
≫ 'TAXI' STO |
|||
≪ → n |
|||
≪ { 0 0 0 } 'LastItem' STO |
|||
{ } DUP 'PQueue' STO 'TaxiNums' STO n n PQAdd |
|||
≫ ≫ 'INIT 'STO |
|||
| |
|||
''( j -- )'' |
|||
Scan the priority queue |
|||
Copy all items except one |
|||
''( -- index { PQ_item } ) |
|||
'' Look for PQ item with max value |
|||
''( x pos -- boolean )'' |
|||
''( r, c -- { PQ_item } )'' |
|||
''( x pos -- boolean )'' |
|||
PQ item = { r^3+c^3 r c } |
|||
''( -- )'' |
|||
Removing max value from queue - and store it if déjà vu |
|||
can we add an item from the row above? |
|||
can we add an item from the left column and above diagonal? |
|||
''( magic_number -- )'' |
|||
initialize global variables |
|||
|} |
|||
The following commands deliver what is required: |
|||
70 INIT TAXI |
|||
TaxiNums |
|||
{{out}} |
|||
<pre> |
|||
1: { { 1729 (9,10) (1,12) } { 4104 (9,15) (2,16) } { 13832 (18,20) (2,24) } { 20683 (19,24) (10,27) } { 32832 (18,30) (4,32) } { 39312 (15,33) (2,34) } { 40033 (16,33) (9,34) } { 46683 (27,30) (3,36) } { 64232 (26,36) (17,39) } { 65728 (31,33) (12,40) } { 110656 (36,40) (4,48) } { 110808 (27,45) (6,48) } { 134379 (38,43) (12,51) } { 149389 (29,50) (8,53) } { 165464 (38,48) (20,54) } { 171288 (24,54) (17,55) } { 195841 (22,57) (9,58) } { 216027 (22,59) (3,60) } { 216125 (45,50) (5,60) } { 262656 (36,60) (8,64) } { 314496 (30,66) (4,68) } { 320264 (32,66) (18,68) } { 327763 (51,58) (30,67) } { 402597 (56,61) (42,69) } } |
|||
</pre> |
</pre> |
||