Distinct power numbers: Difference between revisions
Content added Content deleted
(Added Go) |
m (→{{header|REXX}}: simplified the code.) |
||
Line 59: | Line 59: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX pgm finds and displays distinct power integers: a^b, where a and b are 2≤both≤5*/ |
<lang rexx>/*REXX pgm finds and displays distinct power integers: a^b, where a and b are 2≤both≤5*/ |
||
parse arg |
parse arg lo hi cols . /*obtain optional arguments from the CL*/ |
||
if |
if lo=='' | lo=="," then lo= 2 /*Not specified? Then use the default.*/ |
||
if lo=='' | lo=="," then lo= 2 /* " " " " " " */ |
|||
if hi=='' | hi=="," then hi= 5 /* " " " " " " */ |
if hi=='' | hi=="," then hi= 5 /* " " " " " " */ |
||
if cols=='' | cols=="," then cols= 10 /* " " " " " " */ |
if cols=='' | cols=="," then cols= 10 /* " " " " " " */ |
||
Line 77: | Line 76: | ||
found= 0; idx= 1 /*initialize # distinct power integers.*/ |
found= 0; idx= 1 /*initialize # distinct power integers.*/ |
||
$= /*a list of distinct power integers. */ |
$= /*a list of distinct power integers. */ |
||
do j=0 for mx+1 |
do j=0 for mx+1; if @.j==. then iterate /*Number not found in 1st DO loop? Skip*/ |
||
if @.j==. then iterate /*this number "found" in 1st DO loop?*/ |
|||
found= found + 1; c= commas(j) /*maybe add commas to the number. */ |
found= found + 1; c= commas(j) /*maybe add commas to the number. */ |
||
$= $ right(c, max(w, length(c) ) ) /*add a distinct power number ──► list.*/ |
$= $ right(c, max(w, length(c) ) ) /*add a distinct power number ──► list.*/ |