String transformation 
There are $n$ light bulbs place in circle and colored with Red, Green,
  Blue. After 1 second, from left to right, 2 consecutive bulbs which
  have different color will both change to extant color. After $k$
  second, how the circle of bulbs will look like ?

For example:
After $1$ second, $BRR$ changed to $RBR$
$BRR \to GGR \to GBB \to RBR \to GGR \to...$
I can solve this problem by a computer (simulate how it change second by second), but I don't know what is the most efficient algorithm(s) (is it exist ?), please help me, thanks.
 A: If we interpret our colours as ternary digits, we can come up with a mechanism for handling this fairly easily.
Let's consider pairs of digits, such as 00 or 12. For notation, we will let the first digit be $a$ and the second digit be $b$, so the pair is $ab$. Now, suppose we let $c=2(a+b)\pmod3$. Then here is the table of possible pairs:
00 -> 0
01 -> 2
02 -> 1
10 -> 2
11 -> 1
12 -> 0
20 -> 1
21 -> 0
22 -> 2
Therefore, you replace both digits with $2(a+b)\pmod3$. It does not matter which digit is assigned to which colour.
Now, if we look at what happens with slightly longer runs, we can have some further insight into the way that the system evolves. For three digits (that is, two steps), with a starting value of $abc$, we find (working in mod 3) that the first digit becomes $2(a+b)$, and then the second and third digits become $2(2(a+b)+c) = a+b+2c$. For four digits (three steps), with $d$ for the initial fourth digit, the third and fourth digits become $2(a+b+2c+d)=c+2(a+b+d)$. For five (adding $e$), we get $2(c+2(a+b+d)+e)=a+b+d+2(c+e)$.
This pattern is difficult to simplify... unless we make a nice choice for the arbitrary assignment of colours. If we choose to let the colour of the first light be assigned $a=0$ as its digit, then it is easy to see that the first light will take the value $2b$, the second will be $b+2c$, the third will be $2b+c+2d$, the fourth will be $b+2c+d+2e$, and so on. The pattern becomes quite clear with this choice. Specifically, if we let $a_i$ be the $i$th initial digit ($a_1=0$), and $b_i$ be the $i$th resulting digit, then for a run of $k<n$, we have, for the first $k$ digits,
$$
b_j=\sum_{i=1}^{j} 2^{i+j+1}a_{i+1} \mod 3
$$
and $b_{k+1}=b_k$, of course. That being said, implementing this as an algorithm is best done by utilising the evaluation process of $b_j=\text{mod}(2(b_{j-1}+a_j),3)$, with the wrap-around between lights $n$ and $1$ being handled by simply taking the appropriate modulo on the index $j$. This then simply requires an initial sweep converting the colours to appropriate digits (assign the first light's colour as $0$, then choose the other two however you see fit from there), and conversion back at the end with another sweep.
