function Pascals-Triangle2 { [CmdLetBinding()] param ( # Single parameter is the number of levels [Parameter(Mandatory=$true)][ValidateRange(1, [int]::MaxValue)][int]$Levels ) process { # Create our working array $row = [System.Numerics.BigInteger[]]::new($Levels) # Now for each level for($l = 1; $l -le $Levels; $l++) { # The first index is always 1, and set our previous $iPrevious = $row[0] = 1 for($i = 1; $i -lt $l; $i++) { # Back up the current value $temp = $row[$i] # Add in the previous value $row[$i] += $iPrevious # Swap out the previous $iPrevious = $temp } # Write out our result Write-Output ([string]::Join(' ', ($row | select -First $l))) } } }