RegexWars
Tier 1 · Sorcerermatch

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.

Your pattern0 chars · par 47
//
Flags
Start typing — tests run as you go.0 of 7 visible tests passing
Test cases

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.

  • OO.##
    .O.##
    ...
    must match

    alive with two live neighbours — survives

  • OO.##
    .OO##
    ...
    must match

    alive with three — survives

  • OOO##
    ...##
    ...
    must match

    dead with exactly three — born

  • ...##
    .O.##
    ...
    must not match

    alive and alone — dies

  • OOO##
    .OO##
    ...
    must not match

    alive with four — dies

  • OO.##
    ...##
    ...
    must not match

    dead with only two — stays dead

  • OOO##
    OOO##
    OOO
    must not match

    everything alive — the centre still dies

+ 9 hidden tests, checked when you submit. They are what stops a pattern that only fits the examples above.