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:
say ' index │'center(title, 1 + cols*(w+1) )
say '───────┼'center("" , 1 + cols*(w+1), '─')
@.= .;
do b=lo to hi /* " " B " " " */
x= a ** b; if @.x\==. then iterate
@.x= x;
end /*b*/
do j=1 while words($$)>0; call getMin $$ /*obtain smallest number in the $$ list*/
$= $ right(commas(z), max(w, length(z) ) ) /*add a distinct power number ──► list.*/
if
say
idx=
▲ end /*j*/
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
say '───────┴'center("" , 1 + cols*(w+1), '─')
say
say 'Found ' commas(
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 ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
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:}}
<pre>
|