...

/

Solution: Game of Life

Solution: Game of Life

Let’s solve the Game of Life using the Matrices pattern.

We'll cover the following...

Statement

The Game of Life, also known simply as Life, is a cellular automaton introduced by British mathematician John Horton Conway in 1970.

We are given an m×nm \times n grid representing the board. Each cell has one of two states:

  • 1 → Alive cell

  • 0 → Dead cell

Each cell interacts with its eight neighbors (horizontal, vertical, and diagonal) according to the following rules:

  1. An alive cell with fewer than 2 alive neighbors dies → underpopulation.

  2. An alive cell with 2 or 3 alive neighbors survives → lives to the next generation.

  3. An alive cell with more than 3 alive neighbors dies → overpopulation.

  4. A dead cell with exactly 3 alive neighbors becomes an alive cell → reproduction.

The board is updated using the above rules, with all updates applied simultaneously across the board. This means the next state of the grid is determined from the current state without interference from ongoing updates.

Given the current state of the board, your task is to update the board to reflect its next state.

Note: You do not need to return anything. ...