Pascal's triangle: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed whitespace, used templates for the output sections.)
(Frink)
Line 2,154: Line 2,154:
1 12 66 220 495 792 924 792 495 220 66 12 1
1 12 66 220 495 792 924 792 495 220 66 12 1
1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
</pre>

=={{header|Frink}}==
This version takes a little effort to automatically format the tree based upon the width of the largest numbers in the bottom row. It automatically calculates this easily using Frink's builtin function for efficiently calculating (even large) binomial coefficients with cached factorials and binary splitting.
<lang frink>
pascal[rows] :=
{
widest = length[toString[binomial[rows-1, (rows-1) div 2]]]
for row = 0 to rows-1
{
line = repeat[" ", round[(rows-row)* (widest+1)/2]]
for col = 0 to row
line = line + padRight[binomial[row, col], widest+1, " "]

println[line]
}
}

pascal[10]
</lang>

{{out}}
<pre>
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
</pre>
</pre>