Next highest int from digits: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added commas to the numbers in the output.) |
m (→{{header|REXX}}: simplified code for inner DO loop.) |
||
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( commas(word(n, words(n) ) ) ) |
w= length( commas( word(n, words(n) ) ) ) /*maximum width number (with commas). */ |
||
do j=1 for words(n); y= word(n, j) |
do j=1 for words(n); y= word(n, j) /*process each of the supplied numbers.*/ |
||
masky= mask(y) /*build a digit mask for a supplied int*/ |
masky= mask(y) /*build a digit mask for a supplied int*/ |
||
lim= copies(9, length(y) ) /*construct a LIMIT for the DO loop. */ |
lim= copies(9, length(y) ) /*construct a LIMIT for the DO loop. */ |
||
do #=y+1 to lim until mask(#)==masky /*search for a number that might work. */ |
|||
if verify(y, #) \== 0 then iterate /*does # have all the necessary digits?*/ |
|||
⚫ | |||
if mask(#)\==masky then iterate /*Masks not equal? Then we can't use #*/ |
|||
leave /*have found a valid #, so leave. */ |
|||
⚫ | |||
if #>lim then #= 0 /*if # > lim, then there is no valid #*/ |
if #>lim then #= 0 /*if # > lim, then there is no valid #*/ |
||
Line 302: | Line 300: | ||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
mask: parse arg z, $; @.= 0 /* [↓] build an unsorted digit mask. */ |
mask: parse arg z, $; @.= 0 /* [↓] build an unsorted digit mask. */ |
||
do k=1 for length(z); parse var z _ +1 z; @._= @._ + 1 |
do k=1 for length(z); parse var z _ +1 z; @._= @._ + 1 |
||
end /*k*/ |
end /*k*/ |
||
do m=0 for 10; if @.m==0 then iterate; $= $ || copies(m, @.m) |
do m=0 for 10; if @.m==0 then iterate; $= $ || copies(m, @.m) |
||
end /*m*/; return $ /* [↑] build a sorted digit mask.*/</lang> |
end /*m*/; return $ /* [↑] build a sorted digit mask.*/</lang> |