Largest int from concatenated ints: Difference between revisions

Line 15:
* [http://www.quora.com/Algorithms/What-is-the-most-efficient-way-to-arrange-the-given-numbers-to-form-the-biggest-number Algorithms: What is the most efficient way to arrange the given numbers to form the biggest number?].
* [http://stackoverflow.com/questions/14532105/constructing-the-largest-number-possible-by-rearranging-a-list/14539943#14539943 Constructing the largest number possible by rearranging a list]
 
=={{header|AWK}}==
Works only with gawk 4.0
<lang awk>
function cmp(i1, v1, i2, v2, u1, u2) {
u1 = v1""v2;
u2 = v2""v1;
return (u2 - u1)
}
function largest_int_from_concatenated_ints(X) {
PROCINFO["sorted_in"]="cmp";
u="";
for (i in X) u=u""X[i];
return u
}
 
BEGIN {
split("1 34 3 98 9 76 45 4",X);
print largest_int_from_concatenated_ints(X)
 
split("54 546 548 60",X);
print largest_int_from_concatenated_ints(X)
}
</lang>
{{out}}
<pre>998764543431
6054854654</pre>
 
=={{header|C}}==
Anonymous user