Pascal's Triangle

Published by Mubashir Hassan in

Mubashir was reading about Pascal's triangle on Wikipedia.

In mathematics, Pascal's triangle is a triangular array of the binomial coefficients that arises in probability theory, combinatorics, and algebra.

Mubashir

Formula for Pascal's triangle is given by:

Mubashir

where n denotes a row of the triangle, and k is the position of a term in the row.

Create a function which takes a number n and returns n top rows of Pascal's Triangle flattened into a one-dimensional list.

Examples

pascals_triangle(1) ➞ [1]

pascals_triangle(2) ➞ [1, 1, 1]

pascals_triangle(4) ➞ [1, 1, 1, 1, 2, 1, 1, 3, 3, 1]

Notes

N/A

Watch a quick demo on how Edabit works.