Numbers with equal rises and falls: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add C) |
m (→{{header|REXX}}: added commaization to output numbers.) |
||
Line 617: | Line 617: | ||
append= n>0 /*a flag that is used to append numbers*/ |
append= n>0 /*a flag that is used to append numbers*/ |
||
n= abs(n) /*use the absolute value of N. */ |
n= abs(n) /*use the absolute value of N. */ |
||
call init /* |
call init /*initialize the rise/fall database. */ |
||
do j=1 until #==n; Lm= length(j) - 1 |
do j=1 until #==n; Lm= length(j) - 1 |
||
s= 0 /*initialize the sum of rises/falls. */ |
s= 0 /*initialize the sum of rises/falls. */ |
||
Line 631: | Line 631: | ||
if append then call show /*display a list of N numbers──►term.*/ |
if append then call show /*display a list of N numbers──►term.*/ |
||
else say 'the ' |
else say 'the ' commas(n)th(n) " number is: " commas($) /*show Nth #.*/ |
||
exit 0 /*stick a fork in it, we're all done. */ |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
init: @.= 0; do i=1 for 9; _= i' '; @._= 1; _= '0'i; @._= +1; end /*i*/ |
init: @.= 0; do i=1 for 9; _= i' '; @._= 1; _= '0'i; @._= +1; end /*i*/ |
||
do i=10 to 99; parse var i a 2 b; if a>b then @.i= -1 |
do i=10 to 99; parse var i a 2 b; if a>b then @.i= -1 |
||
else if a<b then @.i= +1 |
else if a<b then @.i= +1 |
||
end /*i*/; #= 0; $=; return |
end /*i*/; #= 0; $=; return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
show: say 'the first ' # " numbers are:"; say; w= length( word($, #) ) |
show: say 'the first ' commas(#) " numbers are:"; say; w= length( word($, #) ) |
||
do o=1 for n; _= _ right( word($, o), w); if o//20\==0 then iterate |
_=; do o=1 for n; _= _ right( word($, o), w); if o//20\==0 then iterate |
||
say substr(_, 2); _= |
say substr(_, 2); _= /*display a line; nullify a new line. */ |
||
end /*o*/ |
end /*o*/ /* [↑] display 20 numbers to a line.*/ |
||
if _\=='' then say substr(_, 2); return /*handle any residual numbers in list. */ |
if _\=='' then say substr(_, 2); return /*handle any residual numbers in list. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
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= when using the default input:}} |
{{out|output|text= when using the default input:}} |
||
<pre> |
<pre> |
||
Line 664: | Line 665: | ||
{{out|output|text= when using the input of: <tt> -10000000 </tt>}} |
{{out|output|text= when using the input of: <tt> -10000000 </tt>}} |
||
<pre> |
<pre> |
||
the |
the 10,000,000th number is: 41,909,002 |
||
</pre> |
</pre> |
||