The Next Generation
A 3×3 patch of Conway's Game of Life. Match it when the centre cell is alive in the next generation.
The patch flattens row-major, top-left first, with (width − 1) hashes between rows: three cells, ##, three cells, ##, three cells. A live cell is a capital O, a dead one a full stop. The rules: a live cell with two or three live neighbours survives, a dead cell with exactly three live neighbours is born, and everything else is dead next turn. Do not enumerate which of the eight neighbours are alive — that is eighty-four alternatives and you will hate all of them. Count. And count the centre cell along with its neighbours rather than apart from them; the two rules collapse into almost one when you do.
Wrapped into rows of 3 so you can see the board. The string itself is one line with no line breaks in it — the 2 # between rows are ordinary characters, and a dot will happily match straight past them.
must matchOO.##.O.##...alive with two live neighbours — survives
must matchOO.##.OO##...alive with three — survives
must matchOOO##...##...dead with exactly three — born
must not match...##.O.##...alive and alone — dies
must not matchOOO##.OO##...alive with four — dies
must not matchOO.##...##...dead with only two — stays dead
must not matchOOO##OOO##OOOeverything alive — the centre still dies
+ 9 hidden tests, checked when you submit. They are what stops a pattern that only fits the examples above.