I was just thinking about brain teasers the other day and came up with this one that turned out to be more difficult than I was anticipating.
Suppose we play a game where we start with a bit string of $l$ zeroes (in my example $l=8$),
00000000
At each step of the game, we choose a bit at random from the bit string and flip it, like
01000000
The game terminates whenever we return back to our initial state of all zeroes. My question is this: What is the (closed-form) expected value of the length of the game as a function of $l$?
My (incomplete) approach:
First, I found the answer for verification purposes by programming the game with a couple different values of $l$ in python, which gave me the hypothesis that the expected value should be $2^l$. My formal proof for how this is the case is what I'm seeking.
I started by conceptualizing the bit string differently, as a string of integers from $0$ to $l-1$ with a dividing line between them. On the LHS of the line would be the indices of 1
in the bit string and the RHS would be indices of 0
in the bit string. This would encode a state like this:
$$
\texttt{10111000}\qquad \Longrightarrow \qquad \texttt{0234 | 1567}
$$
Then, each iteration of the game is simply choosing one of these numbers at random, and putting it on the other side of the dividing line. If we call the set of integers on the LHS $L$ and those on the RHS $R$, then the probability that the line moves left is $|L|\;/\;l$ and the probability that it moves right is $|R|\;/\;l$.
In this sense, we can sort of model the bit-flipping process as a one-dimensional random walk, terminating whenever the walker reaches the LHS, or $|L| = 0$. This is why I consider the process to be a Martingale, even though the probability that the walker moves one direction or the other actually changes depending on where it is. That said, I don't actually know anything about Martingales other than that they are essentially random walks with a terminating condition (like gambling or w/e).
I'm just not sure how to continue from here, can anyone solve this problem?