Smallest numbers: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: simplified some code.) |
(→{{header|Raku}}: Added Raku solution) |
||
Line 4: | Line 4: | ||
Smallest number k > 0 such that the decimal expansion of k^k contains n, where '''n < 51''' |
Smallest number k > 0 such that the decimal expansion of k^k contains n, where '''n < 51''' |
||
<br><br> |
<br><br> |
||
=={{header|Raku}}== |
|||
<lang perl6>sub smallest ( $n ) { |
|||
state @powers = '', |map { $_ ** $_ }, 1 .. *; |
|||
return @powers.first: :k, *.contains($n); |
|||
} |
|||
.say for (^51).map(&smallest).batch(10)».fmt('%2d');</lang> |
|||
{{out}} |
|||
<pre> |
|||
( 9 1 3 5 2 4 4 3 7 9) |
|||
(10 11 5 19 22 26 8 17 16 19) |
|||
( 9 8 13 7 17 4 17 3 11 18) |
|||
(13 5 23 17 18 7 17 15 9 18) |
|||
(16 17 9 7 12 28 6 23 9 24) |
|||
(23) |
|||
</pre> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX pgm finds the smallest positive integer K where K**K contains N, N < 51 */ |
<lang rexx>/*REXX pgm finds the smallest positive integer K where K**K contains N, N < 51 */ |