Largest int from concatenated ints: Difference between revisions

<lang julia></lang>
(<lang julia></lang>)
(<lang julia></lang>)
Line 1,148:
=={{header|Julia}}==
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>
 
<lang julia>function maxconcat{T<:Integer}(arra::VectorArray{<:IntegerT,1})
b = map(string, a)
b = sort(dec.(arr); lt=(x, y) -> x * y < y * x, rev=true) |> join
returnb try= parsesort(Intb, blt=(x,y)->x*y catch< parse(BigInty*x, brev=true) end
b = join(b, "")
try
b = parseint(b)
catch
b = parseint(BigInt, b)
end
end
 
tests = ({[1, 34, 3, 98, 9, 76, 45, 4],
[54, 546, 548, 60],
[1, 34, 3, 98, 9, 76, 45, 4, 54, 546, 548, 60])}
 
for arrt in tests
println("Max concatenating in $arr:\n ->Maxconcating ", maxconcat(arr)t)
println(" ", maxconcat(t))
end</lang>
 
{{out}}
<pre>
<pre>Max concatenating in [1, 34, 3, 98, 9, 76, 45, 4]:
Maxconcating [1,34,3,98,9,76,45,4]
-> 998764543431
Max concatenating in [54, 546, 548, 60]:
Maxconcating [54,546,548,60]
-> 6054854654
Max concatenating inMaxconcating [1, 34, 3, 98, 9, 76, 45, 4, 54, 546, 548, 60]:
-> 9987660548546544543431</pre>
</pre>
 
=={{header|Kotlin}}==
Anonymous user