Task 3 of 5

Generations: Feed It Back

One tick is a snapshot; a world is a movie. A kernel has no memory of the previous frame — time lives in JavaScript. The result of a 2D kernel is an array of rows, which is exactly the shape the kernel accepts as input, so current = await step(current) is the whole time machine: output becomes input, forever.

Your test subject is the R-pentomino — five innocent-looking cells that erupt into chaos (on an infinite grid they don't settle down for 1,103 generations; Conway's group tracked it by hand). You'll run six generations and log the population after each, so you can watch the explosion begin.

the kernel ticks; javascript turns the crank — output straight back in
Goal: restore the B3/S23 rule inside the kernel, then run 6 generations by feeding each output back in — logging 'gen ' + g + ': ' + alive + ' alive' after every step.

Requirements

Hint 1 — the feed-back loop

let current = world; then

for (let g = 1; g <= 6; g++) {
  current = await step(current);
  // …
}

No copying, no bookkeeping — the kernel's output is already a valid input.

Hint 2 — counting the living

Inside the loop, after stepping: let alive = 0; and two nested loops adding current[y][x]. Cells are 0 or 1, so the sum is the population.

Same idea elsewhere

The frame loop lives on the host everywhere: a CUDA fluid sim launches its kernel thousands of times from an ordinary CPU for loop, and a Metal app encodes one compute dispatch per frame — the GPU computes each tick, but the CPU decides that time passes.

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.