Game of Life

Cellular automaton devised by the British mathematician John Horton Conway in 1970.

The other day, this article came across my feed which made me curious about Conway's Game of Life. As per Wikipedia:

The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input. One interacts with the Game of Life by creating an initial configuration and observing how it evolves. It is Turing complete and can simulate a universal constructor or any other Turing machine.

The rules for Life are shown in the chart below. A neighbor is any adjacent item, including diagonals. Think Minesweeper:

Rules

Underpopulation
Live cell with (0-1) living neighbors becomes Dead
Survival
Live cell with (2-3) living neighbors stays Alive
Overpopulation
Live cell with (4+) living neighbors becomes Dead
Zombification
Dead cell with (3) living neighbors becomes Alive

There are many solutions around for this problem; they often use multi-dimensional arrays and nested loops.

I fell the down the rabbit-hole of trying to solve it for a flat array using maps. There was no particular reason for this other than the fact I wanted to. This solution is less about solving the problem the best way as opposed to solving it the way I wanted to solve it; for fun.

How to use

Changing the size of the board will generate a new random set of data. Increase iterations and pay attention to the changing numbers which represent neighbor count and how they follow the rules above.