Smallest power of 6 whose decimal expansion contains n: Difference between revisions
Content added Content deleted
m (added a verb and whitespace to the task requirements..) |
mNo edit summary |
||
Line 4: | Line 4: | ||
Show the smallest power of '''6''' whose decimal expansion contains '''n,''' where '''n < 22''' |
Show the smallest power of '''6''' whose decimal expansion contains '''n,''' where '''n < 22''' |
||
<br><br> |
<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}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX pgm finds the smallest (decimal) power of 6 which contains N, where N < 22. */ |
<lang rexx>/*REXX pgm finds the smallest (decimal) power of 6 which contains N, where N < 22. */ |