Smallest numbers: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: simplified the code. |
|||
Line 688: | Line 688: | ||
if cols=='' | cols=="," then cols= 10 /* " " " " " " */ |
if cols=='' | cols=="," then cols= 10 /* " " " " " " */ |
||
w= 6 /*width of a number in any column. */ |
w= 6 /*width of a number in any column. */ |
||
title=' smallest positive integer K where K**K contains N, 0 ≤ N < ' commas(hi) |
|||
say ' N │'center( |
say ' N │'center(title, 5 + cols*(w+1) ) /*display the title of the output. */ |
||
say '─────┼'center("" |
say '─────┼'center("" , 5 + cols*(w+1), '─') /* " " separator " " " */ |
||
$=; idx= 0 /*define $ output list; index to 0.*/ |
$=; idx= 0 /*define $ output list; index to 0.*/ |
||
do j=0 for hi |
do j=0 for hi /*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). */ |
do k=1 until pos(j, k**k)>0 /*calculate a bunch of powers (K**K). */ |
||
end /*k*/ |
end /*k*/ |
||
c= commas(k) /*maybe add commas to the powe of six. */ |
c= commas(k) /*maybe add commas to the powe of six. */ |
||
$= $ right(c, max(w, length(c) ) ) /*add a K (power) ──► list, allow big#*/ |
$= $ right(c, max(w, length(c) ) ) /*add a K (power) ──► list, allow big#*/ |
||
if |
if (j+1)//cols\==0 then iterate /*have we populated a line of output? */ |
||
say center(idx, 5)'│'substr($, 2); $= /*display what we have so far (cols). */ |
say center(idx, 5)'│'substr($, 2); $= /*display what we have so far (cols). */ |
||
idx= idx + cols /*bump the index count for the output*/ |
idx= idx + cols /*bump the index count for the output*/ |
||
Line 703: | Line 703: | ||
if $\=='' then say center(idx, 5)"│"substr($,2) /*possible display any residual output.*/ |
if $\=='' then say center(idx, 5)"│"substr($,2) /*possible display any residual output.*/ |
||
say '─────┴'center("" |
say '─────┴'center("" , 5 + cols*(w+1), '─') /* " " separator " " " */ |
||
exit 0 /*stick a fork in it, we're all done. */ |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |