Numbers with equal rises and falls: Difference between revisions

m
→‎{{header|REXX}}: elided a blank line, moved one-liner functions to top of subroutine code.
(Added C++ and Swift solutions)
m (→‎{{header|REXX}}: elided a blank line, moved one-liner functions to top of subroutine code.)
Line 1,520:
s= s + @.t /*sum 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. */
Line 1,529 ⟶ 1,528:
else say 'the ' commas(n)th(n) " number is: " commas(j) /*show Nth #.*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do c=length(_)-3 to 1 by -3; _=insert(',', _, c); end; return _
th: parse arg th; return word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))</lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
init: @.= 0; do i=1 for 9; _= i' '; @._= 1; _= '0'i; @._= +1; end /*i*/
Line 1,540 ⟶ 1,542:
end /*o*/ /* [↑] display 20 numbers to a line.*/
 
if _\=='' then say substr(_, 2); return /*handle any residual numbers in list. */</lang>
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do c=length(_)-3 to 1 by -3; _=insert(',', _, c); end; return _
th: parse arg th; return word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>