RegexWars

Codewars, but the only language is regex.

next daily in --:--:--

Tier 1 · SorcerermatchDaily #66

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.

Solve it, then shrink it

Passing is the easy half. Your score is the length of your pattern, so the real competition starts once it turns green.

No accounts, no setup

Everything runs in your browser. Nothing to install, nothing to sign up for, and every challenge is free — permanently.

68 challenges, eight tiers

From matching a literal word to writing the regex that detects prime numbers. Browse them all.

RegexWars — Codewars, but the only language is regex