I have a grid that can be represented as a boolean[][]
, e.g.
new boolean[][] {
{true, false, true, ...},
{false, true, false, ...}
{true, false, true, ...}
...
}
would represent a grid like:
O X O ...
X O X ...
O X O ...
...
where O
is on/alive/true and X is off/dead/false.
The grid is always a rectangle or square of dimensions (length or width) can be a non-trivial length (greater than 20)
The rules of this cellular automation are:
A cell is alive on the next tick if exactly one the following 4 cells are alive on the current tick:
- This cell
- The cell below
- The cell to the right
- The cell below and to the right
In all other conditions, the cell is dead on the next tick.
A special case are the cells on the bottom row and the far-right column of the grid, which are all removed on the next tick.
For example, the input grid of
O X X
X X O
X X X
would be
O O
X O
on the next tick,
So the rules of the game are quite simple.
The question is, from any given position, how can one determine the total number of valid previous ticks that would have evaluated into the current tick?
It is clear if the input is a m x n
grid, one could generate every possible grid combination of a grid size m+1 x n+1
, evaluate the tick and compare the positions. However, this would be a solution that would be 2^(O(m x n))
and there is a lot of redundancy in this approach.
I have coded an approach that calculates every possible bottom row combination and then combines these into a “weighted bottom row” and then it continues to traverse the grid upwards. This removes the duplication of calculating the same results over and over but still clearly could be improved. A similar approach would be to move inwards from the right-hand side or a combination of the two.
My thoughts are that for any given cell, it is only affected by the cells diagonally up-left of the current cell. E.g. on a 10x10
, the combinations of the cells on the previous tick at the bottom left are largely unaffected by the combinations of the cells on the previous tick at the top-right.
Surely there is a way to find the total number of valid previous grids that takes into account the fact that most of cells do not affect each other?
I am mostly looking for an understanding to the approach, rather than any code for a full solution - please go ahead though, if you wish!