Jump to content

Largest int from concatenated ints: Difference between revisions

Line 2,377:
=={{header|Smalltalk}}==
sort by padded print strings:
{{works with|Smalltalk/X}}
<lang smalltalk>#(
(54 546 548 60)
Line 2,401 ⟶ 2,402:
 
resultString :=
((ints copy sort:[:a :b | e'{a}{b}' > e'{b}{a}']) "(1)"
(a printString,b printString) > (b printString,a printString)])
collect:#printString) asStringWith:''.
Stdout printCR: resultString.
].</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):
<lang smalltalk>#(
Line 2,411 ⟶ 2,413:
(1 34 3 98 9 76 45 4)
) do:[:ints |
(ints copy sort:[:a :b | e'{a}{b}' > e'{b}{a}'])
(a printString,b printString) > (b printString,a printString)])
do:[:eachNr | eachNr printOn:Stdout].
Stdout cr.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.