Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

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