Rule 30

Elementary cellular automaton that evolves to chaotic patterns.

Level:Beginner

cellular-automatagrid

  • Probes:ones
simulation.py

Wolfram Rule 30

This simulation iterates the elementary cellular automaton known as Rule 30. Starting from a single active cell, each step applies the bitwise rule. The final grid contains one row for each step so the entire evolution can be viewed at once.


from tys import progress, frame, probe

Run the Rule 30 simulation.

def simulate(cfg: dict):

    width = cfg["width"]
    steps = cfg["steps"]

    state = 1 << (width // 2)
    mask = (1 << width) - 1

    def row_from_state(s: int) -> list[int]:
        return [1 if (s >> (width - 1 - i)) & 1 else 0 for i in range(width)]

    rows: list[list[int]] = []
    for step in range(steps):
        row = row_from_state(state)
        rows.append(row)
        probe("ones", step, sum(row))
        progress(int(100 * (step + 1) / steps))
        state = ((state >> 1) ^ (state | (state << 1))) & mask

    row = row_from_state(state)
    rows.append(row)
    frame(0, rows)
    ones = sum(row)
    return {"ones": ones}


def requirements():
    return {
        "builtin": ["micropip", "pyyaml"],
        "external": []
    }
Default.yaml
width: 128
steps: 128
Charts (Default)

ones

ones chartCSV
Samples128 @ 0.00–127.00
Valuesmin 1.00, mean 49.15, median 58.50, max 80.00, σ 20.85
Final Frame (Default)
final frame
Final Results (Default)
MetricValue
ones68.00