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

m
(add RPL)
m (→‎{{header|Wren}}: Minor tidy)
(6 intermediate revisions by 3 users not shown)
Line 1,350:
20: 170581728179578208256
21: 216</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ 0 swap
[ dip 1+
10 /
dup 0 = until ]
drop ] is digits ( n --> n )
 
[ 10 over digits
** temp put
false unrot
[ over temp share mod
over = iff
[ rot not unrot ]
done
dip [ 10 / ]
over 0 = until ]
2drop
temp release ] is contains ( n n --> b )
 
[ -1 swap
[ dip 1+
over 6 swap **
over contains
until ]
drop ] is smallest ( n --> n )
 
22 times
[ i^ 10 < if sp
i^ echo
say " --> "
6 i^ smallest **
echo cr ]
cr
say "The smallest power of 6 whose decimal expansion contains 31415926 is 6^"
31415926 smallest echo say "." cr</syntaxhighlight>
 
{{out}}
 
<pre> 0 --> 10077696
1 --> 1
2 --> 216
3 --> 36
4 --> 46656
5 --> 46656
6 --> 6
7 --> 7776
8 --> 2176782336
9 --> 1296
10 --> 10077696
11 --> 2821109907456
12 --> 1296
13 --> 13060694016
14 --> 6140942214464815497216
15 --> 101559956668416
16 --> 216
17 --> 60466176
18 --> 470184984576
19 --> 21936950640377856
20 --> 170581728179578208256
21 --> 216
 
The smallest power of 6 whose decimal expansion contains 31415926 is 6^4261.</pre>
 
=={{header|Raku}}==
Line 1,493 ⟶ 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,502 ⟶ 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,544 ⟶ 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,554 ⟶ 1,618:
'''<span style="color:blue">POW6'''</span> ''( n -- { #multi #precision } )''
{ #1d } is 1 in multi-precision
multiply n times
Line 1,562 ⟶ 1,626:
Forces decimal mode for integer display
fornfor n < 22
turn n into string, initialize counter
get 6^n
Line 1,570 ⟶ 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>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">def smallest_6(n)
i = 1
c = 0
s = n.to_s
until i.to_s.match?(s)
c += 1
i *= 6
end
[n, c, i]
end
 
(0..21).each{|n| puts "%3d**%-3d: %d" % smallest_6(n) }
</syntaxhighlight>
{{out}}
<pre> 0**9 : 10077696
1**0 : 1
2**3 : 216
3**2 : 36
4**6 : 46656
5**6 : 46656
6**1 : 6
7**5 : 7776
8**12 : 2176782336
9**4 : 1296
10**9 : 10077696
11**16 : 2821109907456
12**4 : 1296
13**13 : 13060694016
14**28 : 6140942214464815497216
15**18 : 101559956668416
16**3 : 216
17**10 : 60466176
18**15 : 470184984576
19**21 : 21936950640377856
20**26 : 170581728179578208256
21**3 : 216
</pre>
=={{header|Wren}}==
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./big" for BigInt
import "./fmt" for Fmt
 
System.print(" n smallest power of 6 which contains n")
9,476

edits