Pascal's triangle: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added/changed comments and whitespace, optimized the code (for speed), made the code simplier.)
m (added whitespace, used larger font for formulas.)
Line 11: Line 11:
For example, the next row would be 1 (since the first element of each row doesn't have two elements above it), 4 (1 + 3), 6 (3 + 3), 4 (3 + 1), and 1 (since the last element of each row doesn't have two elements above it).
For example, the next row would be 1 (since the first element of each row doesn't have two elements above it), 4 (1 + 3), 6 (3 + 3), 4 (3 + 1), and 1 (since the last element of each row doesn't have two elements above it).


Each row <tt>n</tt> (starting with row 0 at the top) shows the coefficients of the binomial expansion of &nbsp; <big>(x + y)<sup>n</sup></big>.
Each row <tt>n</tt> (starting with row &nbsp; 0 &nbsp; at the top) shows the coefficients of the binomial expansion of &nbsp; <big><big>(x + y)<sup>n</sup></big></big>.




;Task:
;Task:
Write a function that prints out the first n rows of the triangle (with <tt>f(1)</tt> yielding the row consisting of only the element 1).
Write a function that prints out the first n rows of the triangle (with <tt> f(1) </tt> yielding the row consisting of only the element 1).


This can be done either by summing elements from the previous rows or using a binary coefficient or combination function.
This can be done either by summing elements from the previous rows or using a binary coefficient or combination function.


Behavior for &nbsp; <tt> n ≤ 0 </tt> &nbsp; does not need to be uniform, but should be noted.
Behavior for &nbsp; <big><tt> n ≤ 0 </tt></big> &nbsp; does not need to be uniform, but should be noted.