You're playing pinball. When you first shoot a ball it randomly comes down through 1 of 3 gates. When you go through an unlit gate, it lights up. Similarly, a lit gate will go out. What is the expected number of balls you have to throw for all 3 gates to light up?


For example, ball A could go through gate 2, B through gate 3, and C through gate 1. This scenario took 3 rolls and has probability `1/27`.


I've put serious thought into this question twice over the last couple of years but my answer gets more and more complicated until my brain explodes.


**Follow up**


Douglas hit the nail on the head. For kicks, here's the Python script I used as a reality check for both the 2 and 3 gate cases.



```
from random import randint

def pinball(gates):
    trials = []
    for trial in range(10000):
        state = [False for g in range(gates)]
        balls = 0
        while not all(state):
            gate = randint(0, len(state) - 1)
            state[gate] = not state[gate]
            balls += 1
        trials.append(1.0 * balls)
    print sum(trials) / len(trials)

pinball(2)
pinball(3)

```


Expected number of pinballs to light up all 3 channels
This is the average time it takes for a random walk on the 1-skeleton of a cube to reach the opposite vertex. There are more general theories for such values, but you can determine this particular one with a simple set of linear equations. Let $T\_i$ be the expected time from when $i$ lights are lit. You want to determine $T\_0$.


$T\_0 = 1 + T\_1$


$T\_1 = 1 + T\_0/3 + 2T\_2/3$


$T\_2 = 1+ 2T\_1/3 + 0$ 


which has the solution


$\{T\_0=10, T\_1=9, T\_2=7\}$.


