Array – Non-iterative algorithm for one-dimensional life game

Consider a boolean array a[n], where each element is a cell. If one and only one adjacent cell is active, the cell becomes Active (set to true), otherwise it becomes a dead zone (set to false). The first and last cell are considered neighbors.

Given a (n), the size of the array n and a positive integer t, I hope to calculate a[n] after the evolution of the tth generation, but do not use any iterative algorithm on t, which may be very large.

What I have observed: If we define S_k (a [n]) is a cyclic shift that moves a [n] k elements to the right. That is, if 0 <= k <1, then a [0] becomes [k] after one shift. n. Define [n] ^ b [n] as an element-wise xor operation between two Boolean arrays. If w [n] is a Boolean array, the next generation can be expressed as

r(w [n]) = S_{-1}(w[n]) ^ S_1(w[n])

The xor operator^ is associative and commutative. Using this attribute, you can calculate The next generation w [n]

r^2(w[n]) = (S_{-2}(w[n]) ^ S_0(w[n]) ) ^ (S_0(w[n]) ^ S_2(w[n]) )
= S_{-2}(w[n]) ^ S_2(w[n])

If we let s_j = S _ {– j}(w [n])^ S_j(w [n]), there is a pattern

r(w[n]) = s_1
r^2(w[n]) = s_2
r^3(w[n]) = s_3 ^ s_1
r^4(w[n]) = s_4< br />...
r(s_m) = s_(m-1) ^ s_(m+1)

In addition, s_n = 0 (an array of zeros), because the complete loop The shift is the original array. How to use it to derive a non-iterative expression of r^t(w[n])?

Edit: The mode is

[1]
[2]
[1,3]
[4 ]
[3,5]
[2,6]
[1,3,5,7]
[8]

Let us express your input as a column vector a_0 with Z/2Z element size n.

You The next generation vector a_1 can be calculated using matrix multiplication:

a_1 = M.a_0 = |0 1 0 0 ... 0 0 0| |a_01|
| 1 0 1 0 ... 0 0 0| |a_02|
|0 1 0 1 ... 0 0 0| |a_03|
....
|0 0 0 0 ... 0 1 0| |... |
|0 0 0 0 ... 1 0 1| |... |
|0 0 0 0 ... 0 1 0| | a_0n|

Given this recursive relationship, you can use the following formula to calculate the generation at time t:

a_t = M^t. a_0 

And you can easily calculate M^t in O(n^3.log(t)) using repeated squares.

Consider a boolean array a [n], where each element is a cell. If one and only one adjacent cell is active, the cell becomes active in the next generation (set to true), otherwise it becomes a dead zone (set to False). The first and last units are considered neighbors.

Given a [n], the array size n and a positive integer t, I hope to calculate a [after the evolution of the t th generation. n], but don’t use any iterative algorithm on t, which can be very large.

What I have observed: If we define S_k(a [n]) is a [n] shifted to the right by k Cyclic shift of elements. That is, if 0 <= k <1, then a [0] becomes [k] after one shift. ñ. Define [n] ^ b [n] as two Booleans Element-wise xor operation between arrays. If w [n] is a Boolean array, the next generation can be expressed as

r(w[n]) = S_{-1}(w[n]) ^ S_1(w[n])

The xor operator^ is associative and commutative. Using this attribute, you can calculate the next generation w [n]

r^2(w[n ]) = (S_{-2}(w[n]) ^ S_0(w[n])) ^ (S_0(w[n]) ^ S_2(w[n]) )
= S_{- 2}(w[n]) ^ S_2(w[n])

If we let s_j = S _ {– j}(w [n])^ S_j(w [n]), there is A pattern

r(w[n]) = s_1
r^2(w[n]) = s_2
r^3(w[ n]) = s_3 ^ s_1
r^4(w[n]) = s_4
...
r(s_m) = s_{m-1} ^ s_{m+1 }

In addition, s_n = 0 (an array of zeros), because the complete cyclic shift is the original array. How to use it to derive a non-iterative expression of r ^ t(w [n])?

Edit: The mode is

[1]
[2]
[1,3]
[4 ]
[3,5]
[2,6]
[1,3,5,7]
[8]

Let us express your input as a Z/2Z column vector a_0 with element size n.

You can use matrix multiplication to calculate the next generation vector a_1:

p>

a_1 = M.a_0 = |0 1 0 0 ... 0 0 0| |a_01|
|1 0 1 0 ... 0 0 0| | a_02|
|0 1 0 1 ... 0 0 0| |a_03|
....
|0 0 0 0 ... 0 1 0| |... |
|0 0 0 0 ... 1 0 1| |... |
|0 0 0 0 ... 0 1 0| |a_0n|

Given this Recursive relationship, you can use the following formula to calculate the generation at time t:

a_t = M^t. A_0

And you can use repeated squares at Easily calculate M ^ t in O(n ^ 3.log(t)).

Leave a Comment

Your email address will not be published.