Task 2 of 5

One Tick of Life

In 1970 John Conway picked the simplest rules he could find that make a world worth watching. Birth: a dead cell with exactly 3 live neighbors comes alive. Survival: a live cell with 2 or 3 neighbors stays alive. Everything else — lonely or overcrowded — dies. That's the whole game (the notation is B3/S23).

There's a classic bug in CPU implementations: update the grid in place and cells start reading half-new, half-old neighbors. A kernel is immune by construction — every thread reads the old world argument and writes into a brand-new output. The double buffer isn't a technique here; it's what a kernel is.

Goal: finish the kernel so it computes one full generation of Conway's Life — birth on 3, survival on 2 or 3, death otherwise.

Requirements

Hint 1 — start dead

Declare let next = 0;, flip it to 1 in the cases that live, and return next; once at the end. Two ifs cover the whole rulebook.

Hint 2 — the two ifs
if (self === 1 && (count === 2 || count === 3)) next = 1;
if (self === 0 && count === 3) next = 1;

Same idea elsewhere

Reading one buffer while writing another is ping-ponging, and every platform institutionalizes it: WebGPU simulations bind two storage buffers and swap their roles each dispatch, and CUDA solvers keep d_old/d_new device pointers and trade them every launch.

All tasks in Cellular Automata

  1. The Neighbor Census
  2. One Tick of Life
  3. Generations: Feed It Back
  4. Watch the Glider Fly
  5. One Kernel, Every Universe

This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.