Largest int from concatenated ints: Difference between revisions

Content added Content deleted
(First implementation using PL/I.)
(Add NetRexx implementation)
Line 449: Line 449:
6054854654</pre>
6054854654</pre>


=={{header|NetRexx}}==
<lang NetRexx>/* NetRexx */
options replace format comments java crossref symbols nobinary

runSample(arg)
return

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method largestInt(il) public static
ri = ''
wa = ''
-- put the list into an indexed string
wa[0] = il.words
loop ww = 1 to wa[0]
wa[ww] = il.word(ww)
end ww

-- order the list
loop wx = 1 to wa[0] - 1
loop wy = wx + 1 to wa[0]
xx = wa[wx]
yy = wa[wy]
xy = xx || yy
yx = yy || xx
if xy < yx then do
-- swap xx and yy
wa[wx] = yy
wa[wy] = xx
end
end wy
end wx

-- rebuild list from indexed string
loop ww = 1 to wa[0]
ri = ri wa[ww]
end ww
return ri.space(0) -- concatenate the list elements into a single numeric

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
ints = [ -
'1 34 3 98 9 76 45 4', -
'54 546 548 60' -
]
loop il over ints
say largestInt(il).right(20) ':' il.space(1, ',')
end il
return
</lang>
{{out}}
<pre>
998764543431 : 1,34,3,98,9,76,45,4
6054854654 : 54,546,548,60
</pre>
=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>let myCompare a b = compare (b ^ a) (a ^ b)
<lang ocaml>let myCompare a b = compare (b ^ a) (a ^ b)