Largest int from concatenated ints: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added comments in the REXX section header. -- ~~~~)
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentation. -- ~~~~)
Line 290: Line 290:
* the list isn't null
* the list isn't null
<lang rexx>/*REXX pgm constructs largest integer from a list using concatenation.*/
<lang rexx>/*REXX pgm constructs largest integer from a list using concatenation.*/
@. = /*used to signify end-of-lists. */
@. =
@.1 = '{1, 34, 3, 98, 9, 76, 45, 4}'
@.1 = '{1, 34, 3, 98, 9, 76, 45, 4}'
@.2 = '{54, 546, 548, 60}'
@.2 = '{54, 546, 548, 60}'
/* [↓] process all the lists. */
/* [↓] process all the lists. */
do j=1 while @.j\==''; $= /*keep truckin' until exausted. */
do j=1 while @.j\==''; $= /*keep truckin' until exausted. */
z=space(translate(@.j,,'},{')) /*perform some scrubbing on list.*/
z=space(translate(@.j, , '])},{([')) /*perform some scrubbing on list.*/


do while z\=='' /*examine each number in the list*/
do while z\=='' /*examine each number in the list*/
big=word(z,1); index=1 /*assume first number is biggest.*/
big=word(z,1); index=1 /*assume first number is biggest.*/


do k=2 to words(z); x=word(z,k) /*get a num. */
do k=2 to words(z); x=word(z,k) /*get an integer.*/
L=max(length(big),length(x)) /*get max len*/
L=max(length(big), length(x)) /*get max length.*/
if left(x,L,left(x,1))<<left(big,L,left(big,1)) then iterate
if left(x,L,left(x,1)) << left(big,L,left(big,1)) then iterate
big=x; index=k /*we found a new biggie (& index)*/
big=x; index=k /*we found a new biggie (& index)*/
end /*k*/
end /*k*/


z=strip(delword(z,index,1)) /*remove the "maximum" from list*/
z=strip(delword(z, index, 1)) /*remove the "maximum" from list*/
$=$ || big /*append the "maximum" number. */
$=$ || big /*append the "maximum" number. */
end /*while*/
end /*while*/


say right($,30) ' max for: ' @.j
say right($,30) ' max for: ' @.j /*show the "max" integer and list*/
end /*j*/
end /*j*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</lang>
'''output''' when using the default input
'''output'''
<pre>
<pre>
998764543431 max for: {1, 34, 3, 98, 9, 76, 45, 4}
998764543431 max for: {1, 34, 3, 98, 9, 76, 45, 4}