How would you identify the size of a circular turing tape? Came across this interesting problem in one of my interviews. Suppose you have a circular turing tape, i.e. simply a circular array. You do not know the size i.e. the number of cells available in that circular array. 

The array consists only of binary digits. Lets say you are currently at one of the cells. You can read and write on the current cell you are on. You can rotate the array towards the left or right, and you have a counter with you which tells you how far away are you from the original cell that you started off with. So if you go right by x units, the counter will read x units and -x if you go x units to the left. However, you cannot store the value of previous cells you encountered. You may have at max only one unit of external memory at your disposal. For example, if you are at +x, you could compare the value at that +x with the one value you have stored in the external memory. Given that currently all the cells have been randomly assigned either a 0 or a 1.

How would you identify the size of this circular array?
This answer was inspired by YuvalFilums's comment.



I will denote values in the cells with $t$ and $f$ and locations on the tape with $0, 1, 2, \dots$ to avoid confusion.

First, check that the length $\neq 1$. To do this, set the cell under the counter to $f$. Then, move right $1$ cell and set that cell to $t$, and return to $0$, checking if that is $t$. If so you have your answer, otherwise move to $2$ and set that to $f$, and return to $0$.

Second, check that the length $\neq 2$ similarly.

Then repeat the following procedure indefinitely:


Move right until encountering an $f$. Set this to $t$.
Move right one cell and set it to $f$.
Return to $0$. If it is $t$, find the first $f$ after $1$, and move left one cell. This is your answer. Otherwise, repeat.