A row of Pascal's triangle
Build one row of a number triangle from the row above it. About 12 minutes.
No label this time
Pascal's triangle starts with a single 1 at the top. Every row after that begins and ends with 1, and each number in the middle is the sum of the two numbers just above it. Row 0 is 1. Row 1 is 1, 1. Row 2 is 1, 2, 1. Row 3 is 1, 3, 3, 1.
A small hint for this one. You don't need the whole triangle. To make a new row, you only ever need the row just before it, so you can keep just one row and replace it each time.
- row
- 0
Row 0 is just a single 1.
Row 3 of Pascal's triangle is 1, 3, 3, 1. What is the second number of row 4?
- A4
- B3
- C6
Show the answer
4. It is the sum of the two numbers above it: 1 + 3 = 4.
Pascal's row
Return row n of Pascal's triangle as a list. Row 0 is [1]. Every row starts and ends with 1, and each other number is the sum of the two numbers above it in the previous row.
n = 4 → [1, 4, 6, 4, 1]
0 ≤ n ≤ 30