Smallest numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: simplified the code.)
m (→‎{{header|REXX}}: code was added to support the displaying of unique numbers found.)
Line 682: Line 682:


=={{header|REXX}}==
=={{header|REXX}}==
Code was added to display the count of unique numbers found.
<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 */
numeric digits 200 /*ensure enough decimal digs for k**k */
numeric digits 200 /*ensure enough decimal digs for k**k */
Line 691: Line 692:
say ' N │'center(title, 5 + cols*(w+1) ) /*display the title of the output. */
say ' N │'center(title, 5 + cols*(w+1) ) /*display the title of the output. */
say '─────┼'center("" , 5 + cols*(w+1), '─') /* " " separator " " " */
say '─────┼'center("" , 5 + cols*(w+1), '─') /* " " separator " " " */
$=; idx= 0 /*define $ output list; index to 0.*/
u= 0; !.= . /*number of unique #'s found; semaphore*/
$=; idx= 0 /*define $ output list; index to 0.*/
do j=0 for hi /*look for a power of 6 that contains N*/
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*/
if !.k==. then do; u= u+1; !.k=; end /*Is unique? Then bump unique counter.*/
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#*/
Line 704: Line 707:
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("" , 5 + cols*(w+1), '─') /* " " separator " " " */
say '─────┴'center("" , 5 + cols*(w+1), '─') /* " " separator " " " */
say
say commas(u) ' unique numbers found.'
exit 0 /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 718: Line 723:
50 │ 23
50 │ 23
─────┴───────────────────────────────────────────────────────────────────────────
─────┴───────────────────────────────────────────────────────────────────────────

23 unique numbers found.
</pre>
</pre>