Anonymous user
Largest int from concatenated ints: Difference between revisions
Largest int from concatenated ints (view source)
Revision as of 21:59, 28 December 2020
, 3 years ago→{{header|Smalltalk}}
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)"
collect:#printString) asStringWith:''.
Stdout printCR: resultString.
].</lang>
¹ 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}'])
do:[:eachNr | eachNr printOn:Stdout].
Stdout cr.
|