Smallest power of 6 whose decimal expansion contains n: Difference between revisions

→‎{{header|RPL}}: add HP-49 version + formatting
(→‎{{header|RPL}}: add HP-49 version + formatting)
Line 1,557:
 
=={{header|RPL}}==
1980s 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"
Line 1,566:
≪ 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'''
≫ ≫ ‘'''<span style="color:blue">MMULT</span>'''’ 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
‘'''<span style="color:blue">M→STR</span>'''’ STO
{ # 1d } SWAP
WHILE DUP REPEAT
SWAP 6 '''<span style="color:blue">MMULT'''</span> SWAP 1 - END
DROP '''<span style="color:blue">M→STR'''</span>
‘'''<span style="color:blue">POW6</span>'''’ STO
≪ DEC { }
0 21 '''FOR''' n
n →STR -1
DO 1 + DUP '''POW6'''
'''UNTIL''' 3 PICK POS '''END'''
'''<span style="color:blue">POW6'''</span> ROT SWAP + SWAP DROP
NEXT
‘'''<span style="color:blue">TASK</span>'''’ STO
|
'''<span style="color:blue">MMULT'''</span> ''( { #multi #precision } n -- { #multi #precision } )''
initialize stack with empty result number and carry
loop from the lowest digit block
Line 1,608:
'''<span style="color:blue">M→STR'''</span> ''( { #multi #precision } -- "integer" )''
for each digit block
turn it into string, remove both ends
Line 1,618:
'''<span style="color:blue">POW6'''</span> ''( n -- { #multi #precision } )''
{ #1d } is 1 in multi-precision
multiply n times
Line 1,634:
|}
{{inout}}
<pre>
1: { "10077696" "1" "216" "36" "46656" "46656" "6" "7776" "2176782336" "1296" "10077696" "2821109907456" "1296" "13060694016" "6140942214464815497216" "101559956668416" "216" "60466176" "470184984576" "21936950640377856" "170581728179578208256" "216" }
15 TASK1
{ } 1 10 FOR n n WHEN + NEXT
100 WHEN
</pre>
====2000s RPL version====
Big integers are native in this version.
{{works with|HP|49}}
≪ { }
0 21 '''FOR''' n
0
'''WHILE''' 6 OVER ^ →STR n →STR POS NOT
'''REPEAT''' 1 + '''END'''
"'6^" SWAP + STR→ +
'''NEXT'''
≫ '<span style="color:blue">TASK</span>' STO
 
{{out}}
<pre>
1: { 6^9 6^0 6^3 6^2 6^6 6^6 6^1 6^5 6^12 6^4 6^9 6^16 6^4 6^13 6^28 6^18 6^3 6^10 6^15 6^21 6^26 6^3 }
1: { "10077696" "1" "216" "36" "46656" "46656" "6" "7776" "2176782336" "1296" "10077696" "2821109907456" "1296" "13060694016" "6140942214464815497216" "101559956668416" "216" "60466176" "470184984576" "21936950640377856" "170581728179578208256" "216" }
</pre>
 
1,150

edits