Numbers with equal rises and falls: Difference between revisions

m
→‎{{header|REXX}}: simplified the code, optimized for speed.
m (→‎{{header|REXX}}: simplified the code, optimized for speed.)
Line 1,406:
n= abs(n) /*use the absolute value of N. */
call init /*initialize the rise/fall database. */
do j=1 until #==n; Lm= length(j) - 1 /*test integers until we have N of them*/
s= 0 /*initialize the sum of rises/falls. */
do k=1 for Lm; t= substrlength(j,k,2)-1 /*obtain a set of two digs from number.*/
s= s + @.t t= substr(j, k, 2) /*sumobtain thea risesset andof fallstwo indigs thefrom number.*/
end s= s + @.t /*ksum the rises and falls in the number*/
end /*k*/
 
if s\==0 then iterate /*Equal # of rises & falls? Then add it*/
#= # + 1 /*bump the count of numbers found. */
if append then $= $ j /*append to the list of numbers found. */
else $= j /*merely set the last number found. */
end /*j*/
 
if append then call show /*display a list of N numbers──►term.*/
else say 'the ' commas(n)th(n) " number is: " commas($j) /*show Nth #.*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/