Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 605 Bytes

File metadata and controls

27 lines (18 loc) · 605 Bytes

Pascal's Triangle

Generates and displays Pascal's triangle up to row N. See Pascal's triangle — Wikipedia.

Construction

Each entry is the sum of the two entries directly above it. Row n contains the binomial coefficients C(n,0), C(n,1), ..., C(n,n).

Built using dynamic programming — each row is derived from the previous one in O(n) time.

Run

python pascal_triangle.py

Prompts for N and prints the first N+1 rows, centred.

Example (N=4)

        1
      1   1
    1   2   1
  1   3   3   1
1   4   6   4   1