Largest int from concatenated ints: Difference between revisions

(Added Kotlin)
Line 1,507:
[1 34 3 98 9 76 45 4] => [9 98 76 45 4 34 3 1] (concatenated: 998764543431)
[54 546 548 60] => [60 548 546 54] (concatenated: 6054854654)
</pre>
 
=={{header|VBScript}}==
{{trans|BBC BASIC}}
<lang vb>
Function largestint(list)
nums = Split(list,",")
Do Until IsSorted = True
IsSorted = True
For i = 0 To UBound(nums)
If i <> UBound(nums) Then
a = nums(i)
b = nums(i+1)
If CLng(a&b) < CLng(b&a) Then
tmpnum = nums(i)
nums(i) = nums(i+1)
nums(i+1) = tmpnum
IsSorted = False
End If
End If
Next
Loop
For j = 0 To UBound(nums)
largestint = largestint & nums(j)
Next
End Function
 
WScript.StdOut.Write largestint(WScript.Arguments(0))
WScript.StdOut.WriteLine
</lang>
 
{{Out}}
<pre>
F:\>cscript /nologo largestint.vbs 1,34,3,98,9,76,45,4
998764543431
 
F:\>cscript /nologo largestint.vbs 54,546,548,60
6054854654
</pre>
 
Anonymous user