Largest int from concatenated ints: Difference between revisions

Added PowerShell
m (changed the ;C.f.: to a ;See also: (bold) header.)
(Added PowerShell)
Line 1,495:
Largest integer= 998764543431
</pre>
 
=={{header|PowerShell}}==
{{works with|PowerShell|2}}
Using algorithm 3
<lang PowerShell>Function Get-LargestConcatenation ( [int[]]$Integers )
{
# Get the length of the largest integer
$Length = ( $Integers | Sort -Descending | Select -First 1 ).ToString().Length
# Convert to an array of strings,
# sort by each number repeated Length times and truncated to Length,
# and concatenate (join)
$Concat = ( [string[]]$Integers | Sort { ( $_ * $Length ).Substring( 0, $Length ) } -Descending ) -join ''
# Convert to integer (upsizing type if needed)
try { $Integer = [ int32]$Concat }
catch { try { $Integer = [ int64]$Concat }
catch { $Integer = [bigint]$Concat } }
return $Integer
}</lang>
<lang PowerShell>Get-LargestConcatenation 1, 34, 3, 98, 9, 76, 45, 4
Get-LargestConcatenation 54, 546, 548, 60
Get-LargestConcatenation 54, 546, 548, 60, 54, 546, 548, 60</lang>
{{out}}
<pre>998764543431
6054854654
60605485485465465454</pre>
 
=={{header|Prolog}}==