20. Cellular Automata
Complex worlds from simple rules — Conway's Game of Life and beyond
In the late 1940s, John von Neumann was trying to design a self-replicating machine. His colleague Stanislaw Ulam suggested using a discrete grid where each cell follows simple rules based on its neighbors. The result was the first cellular automaton — a theoretical machine that could reproduce itself, built entirely from local interactions on a lattice.
Decades later, in 1970, mathematician John Conway stripped the idea down to its essence. His Game of Life used a 2D grid with just two states (alive or dead) and four rules. It became the most famous cellular automaton in history — a zero-player game that produces gliders, oscillators, and self-replicating patterns from nothing but an initial configuration and relentless iteration.
Then in the 1980s, Stephen Wolfram took things even further. He studied the simplest possible automata — one-dimensional rows of cells with just two states and nearest-neighbor rules — and found that even these trivial systems could produce behavior indistinguishable from randomness, or even perform universal computation. His classification of elementary cellular automata showed that complexity doesn't require complex rules.
Elementary Cellular Automata (1D)
Wolfram's elementary automata are the simplest non-trivial cellular automata. The setup:
- A one-dimensional row of cells, each either 0 (off) or 1 (on)
- Each cell's next state depends on its current state and the states of its two immediate neighbors — a neighborhood of 3 cells
- The same rule applies to every cell simultaneously
Since each of the 3 cells in the neighborhood can be 0 or 1, there are possible neighborhood configurations. A rule is a lookup table that maps each of these 8 configurations to a 0 or 1 output. Since there are 8 entries each with 2 possible values, there are possible rules — numbered 0 through 255.
The rule numbering system
The rule number is the lookup table, read as a binary number. For example, Rule 30:
We line up the 8 possible neighborhoods in descending order (111, 110, 101, 100, 011, 010, 001, 000) and assign each one the corresponding bit from the rule number:
| Neighborhood | 111 | 110 | 101 | 100 | 011 | 010 | 001 | 000 |
|---|---|---|---|---|---|---|---|---|
| Rule 30 output | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 |
To compute the next generation, slide this lookup across every cell in the row. Start from a single black cell and repeat for many generations, stacking each new row below the last — the result is a 2D image where the vertical axis is time.
Notable rules
Rule 30 produces chaotic, aperiodic patterns from a single seed cell. Wolfram used it as a pseudorandom number generator in Mathematica. The left side of the pattern appears completely random, while the right side has some triangular structure.
Rule 90 generates the Sierpinski triangle — a famous fractal. Every cell is the XOR of its two neighbors, producing a perfectly self-similar pattern.
Rule 110 is the most remarkable. Despite its simplicity, it has been proven Turing complete — it can simulate any computation given the right initial conditions. This was proved by Matthew Cook in 2004 and is one of the smallest known universal systems.
Rule 184 models simple traffic flow: cars (1-cells) move right if the cell ahead is empty. It exhibits phase transitions between free-flowing and congested states.
Conway's Game of Life
The Game of Life plays out on an infinite 2D grid. Each cell is either alive (1) or dead (0). The neighborhood is the Moore neighborhood — the 8 cells surrounding a given cell (horizontally, vertically, and diagonally adjacent).
At each tick, every cell updates simultaneously according to four rules:
- Underpopulation — a live cell with fewer than 2 live neighbors dies
- Survival — a live cell with 2 or 3 live neighbors survives
- Overpopulation — a live cell with more than 3 live neighbors dies
- Reproduction — a dead cell with exactly 3 live neighbors becomes alive
That's it. Four rules, applied uniformly, produce an astonishing zoo of behaviors.
Why these exact numbers?
Conway spent two years experimenting with different birth/survival thresholds before settling on B3/S23 (birth on 3 neighbors, survival on 2 or 3). Most rule sets either die out completely or grow without bound. B3/S23 sits at a critical boundary — it supports stable structures, oscillating patterns, and moving objects, all without explosive growth. This delicate balance is what makes Life interesting.
The pattern zoo
Still lifes — patterns that don't change from one generation to the next:
- Block (2x2 square) — the simplest still life. Every live cell has exactly 3 neighbors, every adjacent dead cell has at most 2.
- Beehive — six cells forming a rounded rectangle. Stable because each live cell has 2 or 3 neighbors, and no dead cell has exactly 3.
- Loaf, boat, tub — other common still lifes you'll encounter in any random soup.
Oscillators — patterns that cycle through a fixed sequence of states:
- Blinker (period 2) — three cells in a row toggle between horizontal and vertical. The simplest oscillator.
- Toad (period 2) — two offset rows of three cells that rock back and forth.
- Pulsar (period 3) — a large, symmetric oscillator with 48 cells. One of the most common naturally occurring period-3 patterns.
Spaceships — patterns that translate across the grid:
- Glider — five cells that move one cell diagonally every 4 generations. The most iconic Life pattern. Discovered by Richard Guy in 1970.
- Lightweight spaceship (LWSS) — moves horizontally at (half the speed of light, where is one cell per generation).
Guns — stationary patterns that emit an infinite stream of spaceships:
- Gosper glider gun — discovered by Bill Gosper in 1970, it fires a new glider every 30 generations. Its discovery won Conway's $50 prize for proving that unbounded growth was possible.
Implementation
The standard approach uses double buffering — two copies of the grid. Read from one, write to the other, then swap.
Pseudocode
create grid[rows][cols] initialized to 0
create next[rows][cols] initialized to 0
function countNeighbors(grid, r, c):
count = 0
for dr in [-1, 0, 1]:
for dc in [-1, 0, 1]:
if dr == 0 and dc == 0: skip
nr = (r + dr + rows) mod rows // toroidal wrap
nc = (c + dc + cols) mod cols
count += grid[nr][nc]
return count
function step():
for each cell (r, c):
n = countNeighbors(grid, r, c)
if grid[r][c] == 1:
next[r][c] = (n == 2 or n == 3) ? 1 : 0
else:
next[r][c] = (n == 3) ? 1 : 0
swap grid and next
The toroidal wrapping (modular arithmetic on coordinates) makes the grid wrap around — the top edge connects to the bottom, the left edge to the right. This avoids boundary effects and gives every cell exactly 8 neighbors.
Performance considerations
For a naive implementation, each step is where is the total number of cells. For large grids, the key optimization is to only update cells that might change — a cell far from any live cell won't change state. Techniques like HashLife (invented by Bill Gosper) use memoization to skip ahead exponentially in time, computing generation in roughly the same time as generation .
Try It: Cellular Automata Explorer
Toggle between Conway's Game of Life and Wolfram's elementary automata. In Life mode, click cells to toggle them, load preset patterns, or seed a random configuration. In Elementary mode, choose any rule from 0 to 255.
Emergence and Computation
The Game of Life is Turing complete. Any computation that can be performed by a traditional computer can, in principle, be carried out by a sufficiently large Life grid with the right initial pattern. Logic gates can be built from glider streams — a glider colliding with another glider at the right angle can produce or destroy signals. From gates, you can build wires, clocks, memory, and eventually a full processor.
People have built working computers inside Life, including patterns that simulate Life itself — a self-referential loop that underscores just how much complexity hides in those four rules.
Rule 110, the elementary automaton, is also Turing complete — despite being a one-dimensional system with only 2 states and a 3-cell neighborhood. Matthew Cook's proof in 2004 showed that Rule 110 can simulate cyclic tag systems, which are themselves universal. This makes Rule 110 one of the simplest known Turing-complete systems.
The lesson is profound: computation does not require complex machinery. A uniform grid of identical cells, each following the same trivial rule, can in principle compute anything. This connects cellular automata to deep questions in theoretical computer science about the minimum requirements for universality.
Variations
The Game of Life is one member of a vast family of cellular automata. Changing the rules, neighborhood, or number of states produces dramatically different behavior:
Langton's Ant — a single cell ("ant") moves on a grid, flipping each cell's color as it leaves. Despite the deterministic rule, it produces chaotic behavior for thousands of steps before suddenly building an infinite diagonal highway. It's a simple example of emergent order from chaos.
Brian's Brain — three states: off, on, dying. A cell turns on if exactly 2 neighbors are on; on cells become dying; dying cells turn off. This produces self-perpetuating "sparks" that race across the grid, collide, and spawn new sparks — a much more active system than Life.
Seeds — dead cells with exactly 2 live neighbors become alive; all live cells die immediately. Every live cell exists for only one generation, yet the system produces explosive, chaotic growth from minimal initial conditions.
WireWorld — four states: empty, electron head, electron tail, conductor. Designed to simulate digital logic circuits directly, without the glider-collision tricks needed in Life. Wires, diodes, and logic gates are trivially easy to build.
Continuous automata like SmoothLife replace the discrete grid with continuous space and smooth transition functions. The result looks strikingly organic — blobs that move, divide, and interact like living cells, without any of the grid artifacts of discrete Life.
What's Next
Next we'll explore Voronoi diagrams — partitioning space by proximity to produce the organic tessellations found in nature from giraffe skin to soap bubbles.