Distinct power numbers: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: elided an output line.) |
m (→{{header|REXX}}: used a faster method of listing the numbers in order for larger lists.) |
||
Line 531: | Line 531: | ||
say ' index │'center(title, 1 + cols*(w+1) ) |
say ' index │'center(title, 1 + cols*(w+1) ) |
||
say '───────┼'center("" , 1 + cols*(w+1), '─') |
say '───────┼'center("" , 1 + cols*(w+1), '─') |
||
@.= .; |
@.= .; $$= /*the default value for the @. array.*/ |
||
do a=lo to hi /*traipse through A values (LO──►HI).*/ |
|||
do b=lo to hi /* " " B " " " */ |
do b=lo to hi /* " " B " " " */ |
||
x= a**b; if @.x\==. then iterate |
x= a ** b; if @.x\==. then iterate /*Has it been found before? Then skip.*/ |
||
@.x= x; |
@.x= x; $$= $$ x /*assign power product; append to $$ */ |
||
end /*b*/ |
end /*b*/ |
||
end /*a*/ |
|||
$=; idx= 1 /*$$: a list of distinct power integers*/ |
|||
do j=1 while words($$)>0; call getMin $$ /*obtain smallest number in the $$ list*/ |
|||
$= /*a list of distinct power integers. */ |
|||
$= $ right(commas(z), max(w, length(z) ) ) /*add a distinct power number ──► list.*/ |
|||
do j=0 for mx+1; if @.j==. then iterate /*Number not found in 1st DO loop? Skip*/ |
|||
if j//cols\==0 then iterate /*have we populated a line of output? */ |
|||
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */ |
|||
idx= idx + cols /*bump the index count for the output*/ |
|||
⚫ | |||
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */ |
|||
idx= idx + cols /*bump the index count for the output*/ |
|||
⚫ | |||
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/ |
||
say '───────┴'center("" , 1 + cols*(w+1), '─') |
say '───────┴'center("" , 1 + cols*(w+1), '─') |
||
say |
say |
||
say 'Found ' commas( |
say 'Found ' commas(j-1) title |
||
exit 0 /*stick a fork in it, we're all done. */ |
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 ? |
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ? |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
getMin: parse arg z .; p= 1; #= words($$) /*assume min; # words in $$.*/ |
|||
do m=2 for #-1; a= word($$, m); if a>=z then iterate; z= a; p= m |
|||
end /*m*/; $$= delword($$, p, 1); return /*delete the smallest number.*/</lang> |
|||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |