Pascal's triangle: Difference between revisions

Line 4,147:
A more optimized solution that doesn't require importing, but produces, naturally, uglier output, would look like this:
<lang nim>const ROWS = 10
const TRILEN = toInt(ROWS * (ROWS + 1) / 2) # Sum of arth progression
var triangle = newSeq[Natural](TRILEN) # Avoid reallocations
 
proc printPascalTri(row: Natural, result: var seq[Natural]) =
Line 4,153 ⟶ 4,154:
for i in 2..row-1: add(result, result[^row] + result[^(row-1)])
add(result, 1)
 
echo result[^row..^1]
if row + 1 <= ROWS: printPascalTri(row + 1, result)
 
var triangle = newSeq[Natural](TRILEN) # Avoid reallocations
printPascalTri(1, triangle)</lang>