Smallest numbers: Difference between revisions

→‎{{header|REXX}}: added the computer programming language REXX.
(Created page with "{{Draft task}} ;Task: Smallest number k > 0 such that the decimal expansion of k^k contains n, where '''n < 51''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib.ring"...")
 
(→‎{{header|REXX}}: added the computer programming language REXX.)
Line 4:
Smallest number k > 0 such that the decimal expansion of k^k contains n, where '''n < 51'''
<br><br>
=={{header|REXX}}==
<lang rexx>/*REXX pgm finds the smallest positive integer K where k**k contains N, N < 51 */
numeric digits 200 /*ensure enough decimal digs for k**k */
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 51 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 6 /*width of a number in any column. */
@spiKK= ' smallest positive integer K where k**k contains N, N < ' commas(hi)
say ' N │'center(@spiKK, 5 + cols*(w+1) ) /*display the title of the output. */
say '─────┼'center("" , 5 + cols*(w+1), '─') /* " " separator " " " */
$=; idx= 0 /*define $ output list; index to 0.*/
do j=0 for hi; n= j + 1 /*look for a power of 6 that contains N*/
do k=1 until pos(j, k**k)>0 /*calculate a bunch of powers (K**K). */
end /*k*/
c= commas(k) /*maybe add commas to the powe of six. */
$= $ right(c, max(w, length(c) ) ) /*add a K (power) ──► list, allow big#*/
if n//cols\==0 | j==0 then iterate /*have we populated a line of output? */
say center(idx, 5)'│'substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
end /*j*/
 
if $\=='' then say center(idx, 5)"│"substr($, 2) /*possible display residual output.*/
say '─────┴'center("" , 5 + cols*(w+1), '─') /* " " separator " " " */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
N │ smallest positive integer K where k**k contains N, N < 51
─────┼───────────────────────────────────────────────────────────────────────────
0 │ 9 1 3 5 2 4 4 3 7 9
10 │ 10 11 5 19 22 26 8 17 16 19
20 │ 9 8 13 7 17 4 17 3 11 18
30 │ 13 5 23 17 18 7 17 15 9 18
40 │ 16 17 9 7 12 28 6 23 9 24
50 │ 23
</pre>
 
=={{header|Ring}}==
<lang ring>