Largest int from concatenated ints: Difference between revisions

→‎Tcl: Added implementation
(New draft task and Python solution.)
 
(→‎Tcl: Added implementation)
Line 32:
Numbers: (54, 546, 548, 60)
Largest integer: 6054854654</pre>
 
=={{header|Tcl}}==
<lang tcl>proc intcatsort {nums} {
lsort -command {apply {{x y} {expr {"$y$x" - "$x$y"}}}} $nums
}</lang>
Demonstrating:
<lang tcl>foreach collection {
{1 34 3 98 9 76 45 4}
{54 546 548 60}
} {
set sorted [intcatsort $collection]
puts "\[$collection\] => \[$sorted\] (concatenated: [join $sorted ""])"
}</lang>
{{out}}
<pre>
[1 34 3 98 9 76 45 4] => [9 98 76 45 4 34 3 1] (concatenated: 998764543431)
[54 546 548 60] => [60 548 546 54] (concatenated: 6054854654)
</pre>
Anonymous user