Largest int from concatenated ints: Difference between revisions
Content added Content deleted
(Updated D entry) |
|||
Line 251: | Line 251: | ||
<lang d>import std.stdio, std.algorithm, std.conv, std.array, permutations2; |
<lang d>import std.stdio, std.algorithm, std.conv, std.array, permutations2; |
||
auto maxCat1(in int[] arr) pure { |
auto maxCat1(in int[] arr) pure @safe { |
||
return arr.to!(string[]).permutations.map!join.reduce!max; |
return arr.to!(string[]).permutations.map!join.reduce!max; |
||
} |
} |
||
auto maxCat2(in int[] arr) pure nothrow { |
auto maxCat2(in int[] arr) pure nothrow @safe { |
||
return arr.to!(string[]).sort!q{b ~ a < a ~ b}.join; |
return arr.to!(string[]).sort!q{b ~ a < a ~ b}.join; |
||
} |
} |
||
auto maxCat3(in int[] arr) { |
auto maxCat3(in int[] arr) /*pure nothrow @safe*/ { |
||
immutable maxL = arr.reduce!max.text.length; |
immutable maxL = arr.reduce!max.text.length; |
||
return arr.to!(string[]) |
return arr.to!(string[]) |