Pascal's triangle mod 2 (Sierpinski)

O(n²)

Each cell is computed exactly like Pascal's triangle but the value is taken modulo 2, so only 0 and 1 appear. Odd cells (1) form the visible Sierpinski triangle pattern. The fractal structure emerges because (a+b) mod 2 = a XOR b, so large triangular voids appear at powers-of-2 row counts. With n rows the triangle contains exactly 3^k filled cells where 2^k ≤ n < 2^(k+1).

Number triangle
Press ▶ to run
Edit the input and press Play

How it works

  1. Initialise an empty triangle of n rows
  2. Fill each edge cell with 1
  3. Fill each interior cell with (left-parent + right-parent) mod 2
  4. Observe the Sierpinski fractal in the parity pattern

Pseudocode

1pascalMod2(n):                      # O(n²)2  rows = []3  for r in 0..n-1:4    rows[r] = array of r+1 nulls5    for c in 0..r:6      if c == 0 or c == r:7        rows[r][c] = 1              # edge8      else:9        rows[r][c] = (rows[r-1][c-1] + rows[r-1][c]) % 2