Answer the question
In order to leave comments, you need to log in
How in the game "Life" to determine the previous state of the cells on the current one? (one-dimensional field)?
Actually, the question is the following: How to determine the state 1 move ago by the current state of the cells in the game "Life"?
Cell behavior rules:
1) If a cell has 2 live neighbors, then it dies
2) If there are no live neighbors, then it dies
3) If there is one live neighbor, then the cell becomes alive
4) In other situations, the state of the cell does not change
The move passes simultaneously for all cells. That is, the state of all cells is taken into account in the current move.
The field on which the cells are located is a one-dimensional array.
Let's say the current state is 0 1 1 0 , then the previous one will be 1 0 0 1 .
Out of bounds array, this is a dead neighbor.
Can you please tell me the algorithm for determining the previous state of the field?
Answer the question
In order to leave comments, you need to log in
Let's denote the current state as C[1..N], the previous one as P[1..N], С[0] = P[0] = C[N+1] = P[N+1] = 0 - cells behind outside the field.
At the current step, a cell is alive if and only if at the previous step it had exactly one neighbor, that is, C[i] = P[i-1] xor P[i+1] => P[i+1] = C[i]xor P[i-1].
1. P[0] = 0, C[1] is known => P[2] = P[0] xor C[1]. Now, knowing P[2] one can find P[4] = P[2] xor C[3] or in general:
для i от 1 до N с шагом 2
P[i+1] = P[i-1] xor C[i];
We got all previous values of even cells. для i от N до 1 с шагом -2
P[i-1] = P[i+1] xor C[i];
P[1] = 0; // или 1
для i от 2 до N с шагом 2
P[i+1] = P[i-1] xor C[i];
So, in my opinion, in no way, it is only possible with a certain probability to offer options for which field configuration led to the current state of the field, but without memory, in my opinion, it is impossible to give a deterministic answer.
can not be determined in any way, you
can find one of the states from which you can go to the current
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question