Jump to content

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

m
no edit summary
m (added a verb and whitespace to the task requirements..)
mNo edit summary
Line 4:
Show the smallest power of   '''6'''   whose decimal expansion contains   '''n,'''     where   '''n   <   22'''
<br><br>
 
 
=={{header|Julia}}==
<lang julia>using Formatting
 
digcontains(n, dig) = contains(String(Char.(digits(n))), String(Char.(dig)))
 
function findpow6containing(needle)
dig = digits(needle)
for i in 0:1000
p = big"6"^i
digcontains(p, dig) && return p
end
error("could not find a power of 6 containing $dig")
end
 
for n in 0:21
println(rpad(n, 5), format(findpow6containing(n), commas=true))
end
</lang>{{out}}
<pre>
0 10,077,696
1 1
2 216
3 36
4 46,656
5 46,656
6 6
7 7,776
8 2,176,782,336
9 1,296
10 10,077,696
11 2,821,109,907,456
12 1,296
13 13,060,694,016
14 6,140,942,214,464,815,497,216
15 101,559,956,668,416
16 216
17 60,466,176
18 470,184,984,576
19 21,936,950,640,377,856
20 170,581,728,179,578,208,256
21 216
</pre>
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds the smallest (decimal) power of 6 which contains N, where N < 22. */
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.