• + 2 comments

    The idea to grasp is that after the first time instant (n=1), the grid keeps toggling between 3 possible configurations.

    So after generating the 3 patterns, we need to notice that the patterns keep repeating in the order(set no.) : . . . . . . . . 3 1 2 1 3 1 2 1 3 1 2 1 . . . . . . . . with a net frequency of 4

    So if n is even, print set 1.

    If n is odd and n%4 is 1, print set 3.

    If n is odd and n%4 is 3, print set 2.