Start free

A level · 3 exercises

Python simulation

Follow the rules step by step, exactly as written: keep the state (a grid, a position), and work out the next state from the current one.

When every cell changes at once, build the new grid apart from the old one.

x, y = 0, 0
for move in "NNEES":
    x += {"E": 1, "W": -1}.get(move, 0)
    y += {"N": 1, "S": -1}.get(move, 0)
print(x, y)

Watch for: Changing the grid while still reading it mixes this step with the next.

Exercises

  1. Game of LifeConway's Game of Life on a grid (cells outside the grid are dead).Expert
  2. Robot on a gridA robot starts at (0, 0) facing north.Expert
  3. Rule 30A row of cells evolves by Rule 30: a cell's next state depends on itself and its twoExpert
Start with “Game of Life”