Rat in a Three-Door Maze — Simulation & Theory

A rat faces three doors on each attempt: Door #1: exit in 1 minute, Door #2: back in 3 minutes, Door #3: back in 5 minutes. The rat picks uniformly at random on each try ($1/3$ each).

Theoretical mean
Simulation mean
Trials
0

Maze Animation

Door #1 (Exit) Door #2 (Back 3m) Door #3 (Back 5m) Start
🐭
Exited! Total time: min
Door #1 Exit Door #2 Back (3m) Door #3 Back (5m) Start

Theory via Conditional Expectation

Let $E$ be the expected time (minutes) from the start. Condition on the first door the rat chooses:

$$E=\tfrac{1}{3}(1)+\tfrac{1}{3}(3+E)+\tfrac{1}{3}(5+E) =3+\tfrac{2}{3}E \;\Rightarrow\; E=9\ \text{minutes}.$$

Monte Carlo Simulation

Histogram of total times

One run (log)

Built for teaching conditional expectations and Monte Carlo simulation. Edit the code to explore other door times or probabilities.