Largest int from concatenated ints: Difference between revisions

Content added Content deleted
m (cleaned up section header when entering the REXX example. -- ~~~~)
(+ D entry)
Line 67:
 
<pre>(998764543431 6054854654)</pre>
 
=={{header|D}}==
The three algorithms. Uses the second module from the Permutations Task.
<lang d>import std.stdio, std.algorithm, std.string, std.conv, permutations2;
 
auto maxCat1(in int[] arr) {
return arr.to!(string[]).permutations.map!join.reduce!max;
}
 
auto maxCat2(in int[] arr) {
return arr.to!(string[]).sort!q{b ~ a < a ~ b}.join;
}
 
auto maxCat3(in int[] arr)
in {
assert(arr.dup.sort().equal(arr.dup.sort().uniq), "Not distinct");
} body {
return arr.to!(string[]).sort!q{cmp(a.cycle, b.cycle) > 0}.join;
}
 
void main() {
const lists = [[1, 34, 3, 98, 9, 76, 45, 4], [54, 546, 548, 60]];
[&maxCat1, &maxCat2, &maxCat3].map!(cat => lists.map!cat).writeln;
}</lang>
{{out}}
<pre>[["998764543431", "6054854654"], ["998764543431", "6054854654"], ["998764543431", "6054854654"]]</pre>
 
=={{header|Haskell}}==