The problem in brief
A space station has four floors. Floor 1 and floor 4 are single points; floors 2 and 3 are pentagons whose neighbouring corners are joined by stairs. The top point is joined to all five corners of floor 2, each corner of floor 3 receives two stairs from floor 2, and every corner of floor 3 is joined to the bottom point. Ray starts at the top and, every minute, walks down (or up, or sideways) one staircase chosen uniformly among those at his current vertex. What is the probability that he reaches floor 4 within 3 minutes? There is no input: the program just prints one number.
How you are scored
A single number, compared with the exact probability. Our answer, obtained three independent ways:
First look at the structure
Before computing, count the stairs at each vertex:
- the top point : 5 stairs (one per corner of floor 2);
- a corner of floor 2: 1 (to ) + 2 (pentagon neighbours) + 2 (to floor 3) = 5;
- a corner of floor 3: 2 (from floor 2) + 2 (pentagon neighbours) + 1 (to ) = 5;
- the bottom point : 5.
Every vertex has exactly 5 stairs, there are 12 vertices and stairs: this is the graph of an icosahedron, with and as opposite poles. For the problem to be consistent, each must sit "between" two adjacent corners of floor 2 ( joined to and ), which is exactly how an icosahedron is built.

The key idea
Ray cannot arrive earlier than minute 3, so "within 3 minutes" means "along a shortest route". The distance from to is 3: one step to floor 2, one to floor 3, one to floor 4. Any detour (a sideways step, or a step back up) costs at least one extra minute. So the event is exactly "the first three steps go down, down, down".
Because every vertex has degree 5, every specific 3-step walk has probability . It remains to count shortest routes:
- 5 choices of the corner on floor 2;
- from , 2 stairs lead down to floor 3;
- from that , 1 stair leads to .
That is routes, hence
Equivalently, step by step: the first step always reaches floor 2 (probability 1), the second goes down with probability , the third with probability , and . Multiplying conditional probabilities along the path is the chain rule of probability.
The full solution
solution.py builds the graph explicitly, asserts that every vertex has degree 5 and that there are 30 edges, then checks the answer three ways:
- Path counting: enumerate all walks ; there are 10.
- Exact Markov chain: propagate the probability distribution one minute at a time with fractions, making absorbing so that the curve is the probability of having arrived by minute . It gives
- Monte Carlo: 200 000 simulated walks give (95 % interval), which contains .
The core of the exact computation:
for _ in range(T):
new = {u: F(0) for u in nodes}
new[Q] = dist[Q] # arrived stays arrived
for u in nodes:
if u != Q:
for v in nbr[u]:
new[v] += dist[u] / 5 # uniform choice among 5 stairs
dist = new

The program to submit is one line: print(0.08).
Results
| approach | value | verdict |
|---|---|---|
| counting the 10 shortest routes, | 0.08 | correct |
| exact Markov chain with fractions | 2/25 | correct, agrees |
| Monte Carlo, 200 000 walks | agrees | |
| forget that Ray can go up or sideways (only down) | 1 | wrong: ignores the uniform choice |
| stairs only go up/sideways, never back up () | 1/6 | answers a different, directed version |
| count each once (5 routes instead of 10) | 0.04 | wrong: each is reached from 2 corners |
What to remember
- Draw the graph and count degrees first: here the uniform degree 5 makes every walk of length 3 equally likely, and the hidden icosahedron makes the structure obvious.
- "Within steps" on a graph at distance exactly means "along a shortest path": count shortest paths, multiply by the probability of one path.
- Chain rule of probability: multiply conditional probabilities step by step ().
- A random walk is a Markov chain: propagating a probability vector with the transition matrix gives exact answers for any horizon, the same mechanism behind PageRank and many sampling algorithms.
- Check with a simulation and report its error bar: a Monte Carlo estimate with samples has standard error .