Largest int from concatenated ints: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added comment in the REXX section header. -- ~~~~) |
(D entry: maxCat3 is now less elegant but works with [10, 1010]) |
||
Line 70: | Line 70: | ||
=={{header|D}}== |
=={{header|D}}== |
||
The three algorithms. Uses the second module from the Permutations Task. |
The three algorithms. Uses the second module from the Permutations Task. |
||
<lang d>import std.stdio, std.algorithm, std. |
<lang d>import std.stdio, std.algorithm, std.conv, std.array, permutations2; |
||
auto maxCat1(in int[] arr) { |
auto maxCat1(in int[] arr) { |
||
Line 80: | Line 80: | ||
} |
} |
||
auto maxCat3(in int[] arr) |
auto maxCat3(in int[] arr) { |
||
immutable maxl = arr.reduce!max.text.length; |
|||
in { |
|||
return arr.to!(string[]) |
|||
assert(arr.dup.sort().equal(arr.dup.sort().uniq), "Not distinct"); |
|||
.schwartzSort!(s => s.replicate(maxl/s.length + 1), "a > b") |
|||
} body { |
|||
.join; |
|||
} |
} |
||