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
- Game of LifeConway's Game of Life on a grid (cells outside the grid are dead).Expert
- Robot on a gridA robot starts at (0, 0) facing north.Expert
- Rule 30A row of cells evolves by Rule 30: a cell's next state depends on itself and its twoExpert