Largest int from concatenated ints: Difference between revisions

Content added Content deleted
Line 2,377: Line 2,377:
=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
sort by padded print strings:
sort by padded print strings:
{{works with|Smalltalk/X}}
<lang smalltalk>#(
<lang smalltalk>#(
(54 546 548 60)
(54 546 548 60)
Line 2,401: Line 2,402:


resultString :=
resultString :=
((ints copy sort:[:a :b |
((ints copy sort:[:a :b | e'{a}{b}' > e'{b}{a}']) "(1)"
(a printString,b printString) > (b printString,a printString)])
collect:#printString) asStringWith:''.
collect:#printString) asStringWith:''.
Stdout printCR: resultString.
Stdout printCR: resultString.
].</lang>
].</lang>
&sup1; replace e'{a}{b}' by (a printString,b printString) in dialects, which dp not support embedded expression strings.

no need to collect the resultString; simply print the sorted list (ok, if printing is all we want):
no need to collect the resultString; simply print the sorted list (ok, if printing is all we want):
<lang smalltalk>#(
<lang smalltalk>#(
Line 2,411: Line 2,413:
(1 34 3 98 9 76 45 4)
(1 34 3 98 9 76 45 4)
) do:[:ints |
) do:[:ints |
(ints copy sort:[:a :b |
(ints copy sort:[:a :b | e'{a}{b}' > e'{b}{a}'])
(a printString,b printString) > (b printString,a printString)])
do:[:eachNr | eachNr printOn:Stdout].
do:[:eachNr | eachNr printOn:Stdout].
Stdout cr.
Stdout cr.