# Life is Simple

Problem #56

Tags: games classical arrays

Who solved this?

Emulation of console-based implementation of the Life

The game of Life by John Conway is played on a grid. At start we place several "organisms" into some cells (only one organism per cell), leaving other cells empty. Cells which are touching by side or corner are neighboring, so each organism may have from `0` to `8` neighbors.

After this, at each turn the colony of organisms evolve by the following rules:

• any organism which have less than `2` or more than `3` neighbors will die (not passing to next turn);
• at the same in each empty cell, which is surrounded by exactly `3` neighbor organisms, a new one is born.

It is important, that birth and dying are performed simultaneously. So when programming you need work like this:

• mark all places where new life will be born;
• mark all organisms which will die;
• remove all marked organisms;
• fill all marked empty cells with new organisms.

Instead of marking cells you can store their coordinates in two dedicated arrays or lists to process them later.

Let us see an example:

``````- - - - -      - - - - -      - - - - -
- - - - -      - - X - -      - - - - -
- X X X -  =>  - - X - -  =>  - X X X -
- - - - -      - - X - -      - - - - -
- - - - -      - - - - -      - - - - -
``````

Here is a colony of `3` organisms. Obviously, at the first turn two of them (left and right) should die. However, before dying they will participate in giving birth to another two ones. Really, empty cells just above the central and just below it have exactly `3` neighbors. So after first turn the colony looks the same but rotated by 90°. Of course after second move the configuration will return to exactly such form as it was initially.

In this problem you will run the given configuration for 5 turns and print the number of organisms after each step.

Input data will contain `5` lines of `7` characters each. They represent a `5 by 7` fragment of the game field.
Dash characters `"-"` represent empty cells, while each `"X"` represent a cell containing a live organism.
Answer should contain `5` values separated by spaces - the amounts of live organisms after each turn.

Example:

``````input data:
-------
---XX--
-XXX---
-------
-------

Note: if you will implement the game using a kind of `2D` array, make sure it is large enough and the initial configuration is placed far from edges, so that it will not reach them in `5` moves - otherwise your results could be spoiled.