Largest int from concatenated ints: Difference between revisions

(Added 11l)
Line 2,374:
998764543431
</pre>
 
=={{header|Smalltalk}}==
sort by padded print strings:
<lang smalltalk>#(
(54 546 548 60)
(1 34 3 98 9 76 45 4)
) do:[:ints |
"sort by padded strings (sort a copy - literals are immudatble)"
concatString :=
((ints copy sort:[:a :b |
|pad|
pad := a integerLog10 max:b integerLog10.
(a printString paddedTo:pad with:$0) > (b printString paddedTo:pad with:$0)])
collect:#printString) asStringWith:''.
Stdout printCR:concatString.
].</lang>
alternative: sort by concatenated pair's strings:
<lang smalltalk>#(
(54 546 548 60)
(1 34 3 98 9 76 45 4)
) do:[:ints |
"sort by concatenated pairs (sort a copy - literals are immudatble)"
concatString :=
((ints copy sort:[:a :b |
(a printString,b printString) > (b printString,a printString)])
collect:#printString) asStringWith:''.
Stdout printCR:concatString.
].</lang>
{{out}}
<pre>6054854654
989764543431</pre>
 
=={{header|Tcl}}==
Anonymous user