Solutions
32. Pascal's triangle
Pascal's triangle is a construction representing binomial coefficients. The triangle starts with a row that has a single value of 1. Elements of each row are constructed by summing the numbers above, to the left and right, and treating blank entries as 0. Here is an example of the triangle with five rows:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
To print the triangle, we must:
- Shift the output position to the right with an appropriate number of spaces, so that the top is projected on the middle of the triangle's base.
- Compute each value by summing the above left and right values. A simpler formula is that for a row i and column j, each new value x is...