Largest int from concatenated ints: Difference between revisions

m
→‎{{header|REXX}}: removed the use of a subroutine. -- ~~~~
(→‎{{header|REXX}}: added the REXX language. -- ~~~~)
m (→‎{{header|REXX}}: removed the use of a subroutine. -- ~~~~)
Line 222:
Largest integer: 6054854654</pre>
 
=={{header|REXXPython}}==
<lang rexx>/*REXX pgm constructs largest integer from a list using concatenation.*/
@. =
@.1 = '{1, 34, 3, 98, 9, 76, 45, 4}'
@.2 = '{54, 546, 548, 60}'
/* [↓] process all the lists. */
do j=1 while @.j\==''; $= /*keep truckin' until exausted. */
z=space(translate(@.j,,'{,}')) /*perform some scrubbing on list.*/
do while z\=='' /*examine each*/
$=$ || mx() /*get "max" #.*/
end /*while*/
say right($,30) ' max for: ' @.j
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────MX subroutine───────────────────────*/
mx: procedure expose z; big=word(z,1); index=1
 
do k=2 to words(z); x=word(z,k) /*get a num. */
L=max(length(big),length(x)) /*get max len*/
if left(x,L,left(x,1))>>left(big,L,left(big,1)) then do
big=x
index=k
end
end /*k*/
 
z=strip(delword(z,index,1))
return big</lang>
'''output''' when using the input of: <tt> xxx </tt>
<pre style="overflow:scroll">
998764543431 max for: {1, 34, 3, 98, 9, 76, 45, 4}
6054854654 max for: {54, 546, 548, 60}
</pre>
 
===Python: Compare repeated string method===
<lang python>def maxnumx(x):
Line 275 ⟶ 243:
 
;Output as above.
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm constructs largest integer from a list using concatenation.*/
@. =
@.1 = '{1, 34, 3, 98, 9, 76, 45, 4}'
@.2 = '{54, 546, 548, 60}'
/* [↓] process all the lists. */
do j=1 while @.j\==''; $= /*keep truckin' until exausted. */
z=space(translate(@.j,,'{,},{')) /*perform some scrubbing on list.*/
 
do while z\=='' /*examine each number in the list*/
big=word(z,1); index=1 /*assume first number is biggest.*/
 
do k=2 to words(z); $x=$ || mxword(z,k) /*get "max"a #num. */
do kL=2max(length(big),length(x)) to words(z); x=word(z,k) /*get a num.max len*/
if left(x,L,left(x,1))>><<left(big,L,left(big,1)) then doiterate
big=x; index=k /*we found a new biggie (& index)*/
end /*k*/
 
z=strip(delword(z,index,1)) /*remove the "maximum" from list*/
exit $=$ || big /*stickappend athe fork in"maximum" it, we'renumber. done.*/
end /*while*/
 
say right($,30) ' max for: ' @.j
end /*j*/
/*stick a dofork in whileit, z\=='we're done.*/*examine each*</lang>
'''output''' when using the input of: <tt> xxx </tt>
<pre style="overflow:scroll">
998764543431 max for: {1, 34, 3, 98, 9, 76, 45, 4}
6054854654 max for: {54, 546, 548, 60}
</pre>
 
=={{header|Ruby}}==