Algorithms

Rule 30: a complex pattern from eight answers

One black cell, a white row and eight short rules. Each new row is built from the previous one, yet a symmetric start soon produces an asymmetric pattern. What does the number 30 mean, and how does the pattern grow?

Click an output in the table to change the rule. All cells read the previous row; 0 is white, 1 is black. At 1×, one generation takes 0.3 s.

Current row: 0. Black cells in this row: 1. Cell updates: 0.

Next value at cell 30: 010 → 1 (generation 0 → 1).

Cell indices start at 0. Click the initial row while paused at generation 0 to edit it, or enter an index. Editing restarts the history. Later, click a cell to inspect its column. Outside the finite row, neighbours always read as 0; edge cells still change. The row does not wrap.

Video walkthrough

Time runs down the picture

This cellular automaton is one-dimensional: its state is a single row of zeros and ones. Rows are stacked vertically to show its history. This is not a two-dimensional board like Conway’s Game of Life: a cell reads only its left neighbour, itself and its right neighbour in the previous generation.

0 is white and 1 is black. The orange outline marks the current generation. Every cell of the new row reads the same old row; the entire generation appears together. Seeking restores saved rows.

Why the number 30?

Three binary cells have eight possible neighbourhoods. In descending order they are 111, 110, 101, 100, 011, 010, 001, 000. Rule 30 assigns outputs 0, 0, 0, 1, 1, 1, 1, 0 in that order. Read them as the binary number 00011110: 16 + 8 + 4 + 2 = 30.

100 produces 1, while 110 produces 0. Position matters, not just the number of black cells: two neighbourhoods with the same count can have different outputs. Swapping left and right does not preserve the rule table.

Click any output in the table to flip its bit and change the rule number. There are 2⁸ = 256 such rules, numbered 0 through 255. The initial row and history length are kept, and playback restarts.

The first three updates

With enough zeros around a single 1, the occupied region starts as 1 → 111 → 11001 → 1101111. During the first update, the cells left of the centre, at the centre and right of the centre read 001, 010 and 100: all three give 1. The surrounding 000 neighbourhoods give 0.

Use Inspect to select a column. The text below the scene shows its three source bits and next output. This predicts one value from the current generation; playback still updates the entire row. Black cells counts only the current row, not the whole picture. Cell updates is the generation index multiplied by row width.

Keep the old row intact

Write outputs into a new array. If you overwrite the original while scanning left to right, the next cell reads an already updated left neighbour. That is a different process whose result depends on traversal order. The update invariant is concrete: every neighbourhood comes exclusively from generation t; every output belongs to generation t + 1.

For rule 30, the local table is equivalent to left XOR (center OR right). This formula does not replace synchronous row updates. No random numbers are used: the same rule and starting row always produce the same history. A complicated picture alone does not prove randomness or nonperiodicity.

A finite row and an infinite line

The classic single-cell experiment uses an infinite line. This player stores a finite, editable row of 1–121 cells. Reading beyond either end always returns 0. The edge cells themselves update normally; they are not pinned to white. The ends do not wrap around.

This is a boundary condition, not an exact infinite model for every rule and every time. Rule 30 preserves an empty background, and influence travels at most one cell per generation. A centred seed in a row of width 61 therefore fits its entire growing pattern through generation 30. Later, part of the pattern leaves the row and the finite model can differ from the infinite one.

For other rules, even 000 may output 1, so an infinite white background need not stay white. A shared run represents the finite row and the boundary condition described here. Blank rows below the current generation have not been shown yet; they are not computed zeros.

One generation in code

Encode a neighbourhood as 4·left + 2·center + right, an integer from 0 to 7. Shifting the rule number right selects its bit; & 1 keeps only that bit. Any integer rule from 0 to 255 works. This executable code matches the interactive transition, including zero values beyond the boundaries, and leaves its input array unchanged.

Show the executable model
function nextRow(cells, rule) {
    return cells.map((center, i) => {
        const left = cells[i - 1] ?? 0;
        const right = cells[i + 1] ?? 0;
        const pattern = 4 * left + 2 * center + right;
        return (rule >>> pattern) & 1;
    });
}
let cells = [0, 0, 0, 1, 0, 0, 0];
cells = nextRow(cells, 30);
// [0, 0, 1, 1, 1, 0, 0]
// For rule 30 only: next = left ^ (center | right).

Computation and the cost of seeking

A generation of width W takes O(W) time and O(W) additional space for its output. Computing G generations takes O(G·W) time. If only the last row is needed, working memory remains O(W); storing the whole picture is optional.

For seeking, the player stores G + 1 independent immutable rows, including the initial row: O((G + 1)·W) memory. Scene projection draws the displayed history prefix and uses up to O((G + 1)·W) temporary objects. The educational player is limited to 121 cells and 128 updates. These are interface limits, not limits on cellular automata or bounds on their behavioural complexity.

Try it yourself

Predict the first generation before stepping. Toggle one starting cell and compare the picture. Rule 0 makes the row white after one update; rule 255 makes it black. Enter 90 and compare its pattern with rule 30. Restore the default with Rule 30 · single cell.

Save a link to an interesting frame. It includes the rule, initial row, history length, inspected column, position and speed, and opens paused. The clean page and video export use the same shared player.

Sources