Expected Distance to Escape a Room

Expectation · Medium · Free problem

You are stuck in a room with 4 doors. Two doors lead to freedom: one down a path of length 5 miles, the other 7 miles. The other two doors loop you right back to this same room -- one after 2 miles, the other after 4 miles. At every step you pick a door uniformly at random.

What is the expected total distance you travel before reaching freedom?

Hints

  1. When a looping door returns you to the same room, the future is statistically identical to when you started -- use this to write a single equation for the expected total distance.
  2. Let $E[D]$ be the expected distance. Apply the Law of Total Expectation by conditioning on which of the 4 doors you pick first, each with probability $\frac{1}{4}$.
  3. For the looping doors, $E[D \mid \text{loop of length } k] = k + E[D]$. Substitute all four conditional expectations into the total expectation formula and solve the resulting linear equation for $E[D]$.

Worked Solution

How to Think About It: The key structure here is that when you take a looping door, you end up in exactly the same situation you started in -- same room, same 4 doors, same probabilities. Nothing has changed except you have racked up some extra miles. This memoryless restart is the classic setup for a first-passage expectation equation. Let $E$ be your expected total distance. You write one equation for $E$ by conditioning on the first door chosen, and then solve for $E$ algebraically.

Quick Estimate: Two of the four doors lead to freedom at distances 5 and 7, averaging 6 miles -- but you do not always escape on the first try. The two looping doors cost you 2 and 4 miles on average, so 3 miles wasted before restarting. You escape with probability $1/2$ each round, so the expected number of rounds is 2. Each round costs either an escape (average 6 miles) or a loop (average 3 miles). A rough estimate: you take about 2 rounds, each costing roughly $\frac{1}{2}(6) + \frac{1}{2}(3) = 4.5$ miles, giving $2 \times 4.5 = 9$ miles. That matches the exact answer, so the intuition is clean.

Approach: Set up a fixed-point equation using the Law of Total Expectation, conditioning on the first door picked.

Formal Solution:

Let $D$ be the total distance traveled before reaching freedom. Condition on the first door chosen. Each door is selected with probability $\frac{1}{4}$.

  • Door of length 5: leads to freedom, so $E[D \mid \text{door 5}] = 5$.
  • Door of length 7: leads to freedom, so $E[D \mid \text{door 7}] = 7$.
  • Door of length 2: loops back to the same room. After traveling 2 miles you face the same problem from scratch, so $E[D \mid \text{door 2}] = 2 + E[D]$.
  • Door of length 4: loops back similarly, so $E[D \mid \text{door 4}] = 4 + E[D]$.

By the Law of Total Expectation:

$$E[D] = \frac{1}{4}(2 + E[D]) + \frac{1}{4}(4 + E[D]) + \frac{1}{4}(5) + \frac{1}{4}(7)$$

Expand:

$$E[D] = \frac{1}{4}E[D] + \frac{1}{4}E[D] + \frac{2 + 4 + 5 + 7}{4}$$

$$E[D] = \frac{1}{2}E[D] + \frac{18}{4}$$

$$\frac{1}{2}E[D] = \frac{9}{2}$$

$$E[D] = 9$$

Answer: The expected total distance traveled before reaching freedom is $\boxed{9}$ miles.

Intuition

This problem is a textbook example of the restart argument. Whenever a random process can return you to its starting state -- a failed attempt, a rejected trade, a reconnection event -- you can write a self-referential equation for the expected cost: total cost = cost this round + (probability of restarting) x (total cost again). The key step is recognizing the memoryless restart: after a loop, the system has no memory of what happened, so the remaining expected distance is exactly $E[D]$ again, not some reduced version of it.

In quant work this pattern shows up constantly: expected number of trials until success (geometric distribution), expected time to fill an order under random rejections, first-passage times in Markov chains, and ruin probability calculations. The algebraic move -- writing $E[D]$ on both sides and solving -- is the same every time. Once you spot the restart structure, the rest is just arithmetic.

Open the full interactive solver →