Largest int from concatenated ints: Difference between revisions

Content added Content deleted
m (adding closing parenthesis missing from iterator in for loop.)
m (update for 1.0+)
Line 1,151: Line 1,151:


=={{header|Julia}}==
=={{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.
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(arr::Vector{<:Integer})
<lang julia>function maxconcat(arr::Vector{<:Integer})
b = sort(dec.(arr); lt=(x, y) -> x * y < y * x, rev=true) |> join
b = sort(string.(arr); lt=(x, y) -> x * y < y * x, rev=true) |> join
return try parse(Int, b) catch parse(BigInt, b) end
return try parse(Int, b) catch parse(BigInt, b) end
end
end