After how many cycles does this pattern repeats ? Is there any value of n>3 for which it does not repeat at all?

42 Views Asked by At

I have N numbers in an array A. The numbers are either 0 or 1 and given that A[1]=0 as well as A[N]=0.

In every operation the array changes as follows:

  • If a cell has two adjacent values that are both equal, then the value becomes 1.
  • Otherwise it becomes 0.
  • First and last cells always remain 0.

Example:

[0,0,1,0,1,0]

[0,0,1,1,1,0]

[0,0,0,1,0,0]

[0,1,0,1,0,0]

[0,1,1,1,0,0]

[0,0,1,0,0,0]

[0,0,1,0,1,0]

Is is possible to derive a general formula f(N) for the number of iteration after which the pattern will repeat itself.