Smallest power of 6 whose decimal expansion contains n: Difference between revisions
Content deleted Content added
m →{{header|Free Pascal}}: saving used strings seperate.( 8 digits takes 2,8 GB ) ready for lunch... |
add RPL |
||
Line 1,490: | Line 1,490: | ||
done... |
done... |
||
</pre> |
|||
=={{header|RPL}}== |
|||
RPL can only handle 64-bit unsigned integers, which means a multi-precision multiplication is here required. |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! RPL code |
|||
! Comment |
|||
|- |
|||
| |
|||
≪ 1000000000 → x n p |
|||
≪ { } # 0d |
|||
x SIZE 1 FOR j |
|||
x j GET n * + |
|||
DUP p / SWAP OVER p * - ROT + SWAP |
|||
-1 STEP |
|||
IF DUP # 0d ≠ THEN SWAP + ELSE DROP END |
|||
≫ ≫ ‘'''MMULT'''’ STO |
|||
≪ "" SWAP |
|||
1 OVER SIZE FOR d |
|||
DUP d GET →STR 3 OVER SIZE 1 - SUB |
|||
IF d 1 ≠ THEN |
|||
WHILE DUP SIZE 9 < REPEAT "0" SWAP + |
|||
END END |
|||
ROT SWAP + SWAP |
|||
NEXT DROP |
|||
≫ ‘'''M→STR'''’ STO |
|||
≪ |
|||
{ # 1d } SWAP |
|||
WHILE DUP REPEAT |
|||
SWAP 6 '''MMULT''' SWAP 1 - END |
|||
DROP '''M→STR''' |
|||
≫ ‘'''POW6'''’ STO |
|||
≪ DEC { } |
|||
0 21 FOR n |
|||
n →STR -1 |
|||
DO 1 + DUP '''POW6''' |
|||
UNTIL 3 PICK POS END |
|||
'''POW6''' ROT SWAP + SWAP DROP |
|||
NEXT |
|||
≫ ‘'''TASK'''’ STO |
|||
| |
|||
'''MMULT''' ''( { #multi #precision } n -- { #multi #precision } )'' |
|||
initialize stack with empty result number and carry |
|||
loop from the lowest digit block |
|||
multiply block by n, add carry |
|||
prepare carry for next block |
|||
if carry ≠ 0 then add it as a new block |
|||
'''M→STR''' ''( { #multi #precision } -- "integer" )'' |
|||
for each digit block |
|||
turn it into string, remove both ends |
|||
if not the highest block |
|||
fill with "0" |
|||
add to previous blocks' string |
|||
'''POW6''' ''( n -- { #multi #precision } )'' |
|||
{ #1d } is 1 in multi-precision |
|||
multiply n times |
|||
by 6 |
|||
make it a string |
|||
Forces decimal mode for integer display |
|||
forn < 22 |
|||
turn n into string, initialize counter |
|||
get 6^n |
|||
until "n" in "6^n" |
|||
remake n a string and add it to result list |
|||
|} |
|||
{{in}} |
|||
<pre> |
|||
15 TASK1 |
|||
{ } 1 10 FOR n n WHEN + NEXT |
|||
100 WHEN |
|||
</pre> |
|||
{{out}} |
|||
<pre> |
|||
1: { "10077696" "1" "216" "36" "46656" "46656" "6" "7776" "2176782336" "1296" "10077696" "2821109907456" "1296" "13060694016" "6140942214464815497216" "101559956668416" "216" "60466176" "470184984576" "21936950640377856" "170581728179578208256" "216" } |
|||
</pre> |
</pre> |
||