Pascal’s Triangle

2016-03-26, post № 111

mathematics, programming, Pygame, Python, #crown, #generate, #sequence

Pascal’s triangle is an interesting mathematical sequence. It is often written as a triangle, starting with \{1\}, then \{1,1\}. To generate the next row, you add the two numbers above to form another one. So the next row in the sequence is \{1,2,1\} then \{1,3,3,1\}, \{1,4,6,4,1\} and so on (sequence A007318 in OEIS).

One interesting property of Pascal’s triangle is the generation of binomials.
To calculate (a+b)^4, you can look at the 𝟦-th row (listed above and when starting to count at 𝟢) and determine

(a+b)^4=(1\cdot a^4\cdot b^0)+(4\cdot a^3\cdot b^1)+(6\cdot a^2\cdot b^2)+(4\cdot a^1\cdot b^3)+(1\cdot a^0\cdot b^4)

This program generates Pascal’s sequence in a rather unusual shape, looking a bit like a crown.

To get more information about Pascal’s triangle, check out this Wikipedia entry.


  • ‘F1’ advances the sequence,
  • ‘Space’ takes a screenshot.
Source code: pascals-triangle.py



  1. In pascals-triangle_pascal.py there is a typo: ‘sedonds’ should say ‘seconds’.
Jonathan Frech's blog; built 2024/05/27 06:43:58 CEST