Next highest int from digits: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: added the REXX computer programming language for this task.)
m (→‎{{header|REXX}}: added commas to the numbers in the output.)
Line 282: Line 282:
parse arg n /*obtain optional arguments from the CL*/
parse arg n /*obtain optional arguments from the CL*/
if n='' | n="," then n= 0 9 12 21 12453 738440 45072010 95322020 /*use the defaults? */
if n='' | n="," then n= 0 9 12 21 12453 738440 45072010 95322020 /*use the defaults? */
w= length(word(n, words(n) ) ) /*max width number. */
w= length( commas(word(n, words(n) ) ) ) /*maximum width number (with commas). */


do j=1 for words(n); y= word(n, j) /*process each of the supplied numbers.*/
do j=1 for words(n); y= word(n, j) /*process each of the supplied numbers.*/
Line 295: Line 295:


if #>lim then #= 0 /*if # > lim, then there is no valid #*/
if #>lim then #= 0 /*if # > lim, then there is no valid #*/
say 'for ' right(y, w)", the next highest integer is: " right(#, w)
say 'for ' right(commas(y),w) " ─── the next highest integer is: " right(commas(#),w)
end /*j*/
end /*j*/
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do c=length(_)-3 to 1 by -3; _=insert(',', _, c); end; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
mask: parse arg z, $; @.= 0 /* [↓] build an unsorted digit mask. */
mask: parse arg z, $; @.= 0 /* [↓] build an unsorted digit mask. */
Line 306: Line 308:
{{out|output|text=  when using the default inputs:}}
{{out|output|text=  when using the default inputs:}}
<pre>
<pre>
for 0, the next highest integer is: 0
for 0 ─── the next highest integer is: 0
for 9, the next highest integer is: 0
for 9 ─── the next highest integer is: 0
for 12, the next highest integer is: 21
for 12 ─── the next highest integer is: 21
for 21, the next highest integer is: 0
for 21 ─── the next highest integer is: 0
for 12453, the next highest integer is: 12534
for 12,453 ─── the next highest integer is: 12,534
for 738440, the next highest integer is: 740348
for 738,440 ─── the next highest integer is: 740,348
for 45072010, the next highest integer is: 45072100
for 45,072,010 ─── the next highest integer is: 45,072,100
for 95322020, the next highest integer is: 95322200
for 95,322,020 ─── the next highest integer is: 95,322,200
</pre>
</pre>