Pascal's row
Inputs
n is a whole number from 0 to 12.
Your tasks
- Create a list
rowthat starts as [1]. - Repeat
ntimes: build a new list that starts with 1, then adds each pair of neighbours inrow, then ends with 1. Replacerowwith the new list. - Complete
pascalRowso it returnsrow. Return it, do not print it.
Example
With n = 4, pascalRow returns [1, 4, 6, 4, 1].
Rules
- Row 0 is [1]. Row 1 is [1, 1]. Row 2 is [1, 2, 1].
Test data
TEST DATA 1: n is 4
TEST DATA 2: n is 0
Practice focus
Nested loops compare every pair and build rows. The slow, simple answer to most problems is two loops. Knowing it is what lets you see how to beat it.