Largest int from concatenated ints: Difference between revisions

Line 1,826:
<pre>Max Num 1, 34, 3, 98, 9, 76, 45, 4 = 998764543431
Max Num 54,546,548,60 = 6054854654</pre>
 
 
=={{header|S-lang}}==
<lang S-lang>define catcmp(a, b)
{
a = string(a);
b = string(b);
return strcmp(b+a, a+b);
}
define maxcat(arr)
{
arr = arr[array_sort(arr, &catcmp)];
variable result = "", elem;
foreach elem (arr)
result += string(elem);
return result;
}
 
print("max of series 1 is " + maxcat([1, 34, 3, 98, 9, 76, 45, 4]));
print("max of series 2 is " + maxcat([54, 546, 548, 60]));
</lang>
{{out}}
<pre>"max of series 1 is 998764543431"
"max of series 2 is 6054854654"
</pre>
 
=={{header|Scala}}==
Anonymous user