I am not proficient in R, so here is my outline:

Function countmoves

Have a vector $v$ that stores two integers. Initialize it to $(1,1)$.

Start a counter at zero.

Start loop

Pick a random number $a$ (1 or 2). Then pick a random number $b$ (1 through 8). If $v[a]=b$ pick a new $a,b$ (restart loop). Otherwise, increase counter by one and set $v[a]=b$. If $v[1]=v[2]=8$ return counter.

End loop

End function

Now, run this function say 500 times and take the average.