Anonymous user
Largest int from concatenated ints: Difference between revisions
Minor fix
Walterpachl (talk | contribs) m (→Version 4: further improvement z/1 is better than z+0 courtesy GS) |
(Minor fix) |
||
Line 1,172:
=={{header|Julia}}==
{{works with|Julia|0.6}}
Perhaps algorithm 3 is more efficient, but algorithm 2 is decent and very easy to implement in Julia. So this solution uses algorithm 2.
<lang julia>function maxconcat
b = sort(dec.(arr); lt=(x, y) -> x * y < y * x, rev=true) |> join
end
tests =
[54, 546, 548, 60],
[1, 34, 3, 98, 9, 76, 45, 4, 54, 546, 548, 60]
for
println("
end</lang>▼
▲</lang>
{{out}}
<pre>Max concatenating in [1, 34, 3, 98, 9, 76, 45, 4]:
Max concatenating in [54, 546, 548, 60]:
▲ 998764543431
▲ 6054854654
▲Maxconcating [1,34,3,98,9,76,45,4,54,546,548,60]
▲ 9987660548546544543431
=={{header|Kotlin}}==
|