LIFE is a multicellular communal organism that inhabits the deserts of Flatland. The desert is organized in a square array with each square capable of holding one LIFE cell. LIFE generations mark the passage of time, each generation bringing births and deaths to the LIFE community.

To follow the history of such a community, place LIFE cells into their initial positions in the desert. Count the passing generations by observing these rules.

  1. The immediate neighbors of a cell are those cells occupying the eight horizontally, vertically, and diagonally adjacent cells.
  2. If a LIFE cell has fewer than two immediate neighbors, it dies of loneliness. If a LIFE cell has more than three immediate neighbors, it dies of overcrowding.
  3. If an empty square has exactly three LIFE cells as immediate neighbors, a new cell is born in the square.
  4. Births and deaths all take place exactly at the change of generations. Thus a dying cell may help birth a new one, but a newborn cell may not resurrect a dying cell, nor may one dying cell stave off death for another by lowering the local population density.

Write a program that simulates a LIFE community for a 10 x 10 colony. Enter the initial position of the community's cells (i.e., a table of 1's and 0's).

When computing the neighbors of a cell on the border, you cannot access all 9 neighbors. A solution to this problem is to maintain an outer border of 0s. Notice that rule 4 indicates that you cannot use any information from generation "I" to compute generation "I+1" but must only use information from generation "I-1". The easiest solution to this problem is the use of a temporary grid.

Study the solution given here.