From Missing the Subway to a Small Probability Model
· 42 min read · Views --

From Missing the Subway to a Small Probability Model

Author: Alex Xiang


For four Saturday mornings in a row, I almost caught Subway Line 18, and then watched the doors close and the train leave.

The person who was “just a little bit late” four times in a row was me.

At first, this was just an ordinary commuting frustration. But after calculating the probability, it started to feel less ordinary. If someone can land in such a narrow unlucky window four times in a row, the probability is low enough that I should at least consider buying a lottery ticket on the way.

Small everyday incidents are often good material for mathematical modeling, especially when they happen to you.

Suppose that around 9 a.m. on Saturday, Subway Line 18 has a headway of about 10 minutes. The train stays at the platform for 30 seconds. A person runs at 3 meters per second. If a passenger is within a distance that allows them to run into the train during those 30 seconds, we say they can catch the train. What is the probability of catching it? What is the probability of catching it four times in a row?

Conversely, suppose that at the exact moment the doors close, the passenger is within 50 meters of the train but still fails to catch it. Call that “very unlucky.” What is the probability of being very unlucky once? What about four times in a row?

Here are the results from the minimal model. After seeing this table, the phrase “I was just a little late for four Saturdays in a row” feels different.

QuestionProbability
Catch the train once5%
Catch it 4 times in a row0.000625%, about 1 in 160,000
Very unlucky once2.78%
Very unlucky 4 times in a row0.0000595%, about 1 in 1,680,000

These numbers are not guesses. They come from a standard “favorable time window divided by total cycle” model.

But that is also what makes the problem interesting. If we only use the information given in the prompt, the calculation is very simple. If we also model “how far the passenger is from the door”, “which entrance they used”, and “whether the path is clear enough to run”, it immediately becomes a probability model with a spatial distribution, and may even require integration.

So this article does more than compute a number. It treats the problem as a small mathematical modeling case: start with the minimal model, then discuss how the model could be extended.

The Original Prompt

This article came from the following question. I am keeping the original prompt here so it is easier to review how Codex turns a natural-language problem into a computable model.

需要解决一个数学问题:假设每周六早上9点左右地铁18号线的发车间隔是10分钟,列车在站台上停车时间为30秒,如果乘客在这30秒内位于能够跑步达到车内的距离,就认为乘客能赶上车,人的跑步速度假设为每秒3米,帮我计算这个时间点赶上18号线地铁的概率,连续4次都能赶上的概率是多少。另一个问题,同样的假设,如果乘客在列车关门的这一刻,正好位于距离列车50米之内的距离而没能赶上列车,认为这个乘客是非常倒霉,计算一下非常倒霉的概率,再计算一下连续四次倒霉的概率。整个分析和计算结果生成一篇博客文章,包括输入给codex的prompt指令。

From Natural Language to a Mathematical Model

The prompt gives three numbers:

  • Headway: 10 minutes, or 600 seconds
  • Dwell time: 30 seconds
  • Running speed: 3 meters per second

It also gives a rule: if the passenger is within a distance that can be covered by running during the 30-second dwell time, the passenger can catch the train.

This sentence hides two variables.

The first is time: at which second after the doors open does the passenger reach the runnable area?

The second is distance: at that moment, how far is the passenger from a position where they can enter the train?

In symbols:

H = 600 seconds      train cycle
S = 30 seconds       dwell time with doors open
v = 3 m/s            running speed
D = 50 meters        "very unlucky" distance threshold
T = passenger arrival time within one train cycle
X = passenger distance from the train door at arrival

Now “can catch the train” is not just a phrase. It becomes an inequality:

0 <= T <= S
and
X <= v × (S - T)

In plain language: you must arrive while the doors are still open, and the remaining open-door time must be enough for you to run the remaining distance.

“Very unlucky” can also be written as a window: the doors have just closed, but at 3 meters per second you were less than 50 meters away, meaning you were less than 16.67 seconds of running away.

0 < T - S <= D / v

At this point, the problem has turned from a life description into a probability model.

Minimal Model: Time Only

In plain language, we assume you did not deliberately time your arrival and did not check real-time train information. Your arrival near the platform is treated as a random point inside a 600-second train cycle.

The minimal model makes two simplifications.

First, it only looks at time, not platform space. If the passenger falls inside the 30-second open-door window, we treat them as already within runnable distance.

Second, arrival time is uniformly distributed within the 600-second cycle. Every second is equally likely.

This makes the problem clean: probability equals favorable time window divided by total cycle.

A more realistic probability would require more information: platform length, entrance-to-door distance, which entrance passengers usually use, where passengers appear on the platform, stairs or elevators, whether running is possible, and whether trains are on time. The prompt does not provide these values, so this article does not invent them.

That is an important modeling principle: do not pretend to know missing information. You can list it as a model extension, but do not force it into the minimal calculation.

Does This Require Calculus?

The minimal model does not require calculus. It only needs division:

Probability = favorable time window / total time window

But if we introduce the distance variable X, integration appears naturally.

In a more complete model, passenger arrival time T is random between 0 and 600 seconds, and distance X has its own distribution. The condition for catching the train is:

0 <= T <= S
X <= v × (S - T)

If F_X(x) is the cumulative distribution function of distance X, meaning the probability that distance is no more than x, then:

P(catch) = (1 / H) × ∫[0 to S] F_X(v × (S - t)) dt

That is an integral.

It is not mysterious. For every second while the doors are open, we ask how far the remaining time allows a person to run, then calculate what fraction of passengers are within that distance, and finally add those possibilities across the 30-second open-door window.

If we further assume X is uniformly distributed from 0 to L meters, and L is greater than 90 meters, then:

F_X(x) = x / L
P(catch) = (1 / H) × ∫[0 to S] v × (S - t) / L dt
         = v × S^2 / (2 × L × H)

Now running speed is no longer just an explanatory detail. It directly enters the probability formula.

But the prompt gives neither L nor the distribution of X. So the formal answer still uses the minimal time-window model. The integral version only shows where a more serious mathematical model would go.

Probability of Catching the Train

Back to the minimal model. The train stays for 30 seconds. If the passenger is within runnable distance during those 30 seconds, they catch the train.

At 3 meters per second, if the doors have just opened, the maximum runnable distance is:

3 m/s × 30 s = 90 m

So the running speed gives a spatial interpretation: at the moment the doors open, if you are within about 90 meters of the door, and there is no obstacle, theoretically you can make it into the train.

In the minimal model, the distance condition is folded into the prompt’s assumption and is not modeled separately. The probability is determined by the time window. One train cycle is 600 seconds, and the catchable window is 30 seconds:

P(catch once) = 30 / 600 = 0.05 = 5%

Catchable window inside a 10-minute train cycle.

This 5% is intuitive. In a 10-minute cycle, only half a minute has the train standing at the platform with doors open. If you arrive randomly, landing in that half-minute window is a 1-in-20 event.

Written as an integral, the minimal model is:

P(catch once) = (1 / 600) × ∫[0 to 30] 1 dt
              = 30 / 600
              = 5%

The integrand is 1, meaning the model treats all conditions as satisfied within the 30-second window and not satisfied outside it. Because the integrand is constant, the integral collapses back to simple division.

If the four trips are independent, the probability of catching the train four times in a row is:

P(4 catches in a row) = 0.05^4
                     = 0.00000625
                     = 0.000625%

In a more intuitive form:

1 / 160000

That is about one in 160,000.

This does not mean catching a train on time four days in a row. It means that under this simplified model, each arrival is random, and each one lands in the 30-second open-door window. That is already a very small probability.

Probability of Being “Very Unlucky”

The second question is more interesting.

The prompt defines “very unlucky” as: at the exact moment the doors close, the passenger is within 50 meters of the train but still fails to catch it.

This is originally a spatial condition. To convert it into a time window using the given speed:

50 m / 3 m/s = 16.666... s

In other words, if you are within 50 meters when the doors close, you are less than 16.67 seconds of running away. As a time-window interpretation, you missed the closing moment, but only by a very narrow 16.67-second window.

So the “very unlucky” window is 16.67 seconds. The full cycle is still 600 seconds:

P(very unlucky once) = 16.666... / 600
                     = 0.027777...
                     = 2.78%

As an integral:

P(very unlucky once) = (1 / 600) × ∫[30 to 46.666...] 1 dt
                     = 16.666... / 600
                     = 2.78%

This is not a mysterious event. It is simply a narrow window immediately after door closing.

The very unlucky window implied by being within 50 meters after doors close.

This probability is smaller than the 5% chance of catching the train, but not absurdly small. It is about one in 36.

2.78% ≈ 1 / 36

So occasionally arriving just after the doors close is not supernatural. It is expected to happen sometimes.

What is extreme is doing it four times in a row.

P(very unlucky 4 times in a row) = (1/36)^4
                                = 1 / 1679616
                                ≈ 0.000000595
                                ≈ 0.0000595%

That is about one in 1.68 million.

If someone takes the train at the same time for four Saturdays in a row, and every time they are within 50 meters when the doors close but still miss it, then it is probably not just “bad luck today.” Either their departure rhythm consistently lands in a terrible position, or the random-arrival assumption is no longer true.

Why Repeated Events Are Multiplied

Many probability problems go wrong at the “several times in a row” step.

If each event is independent, the probability of repeated occurrence is the product of the individual probabilities.

Catching the train once is 5%, so catching it four times in a row is:

5% × 5% × 5% × 5%

Being very unlucky once is 2.78%, so being very unlucky four times in a row is:

2.78% × 2.78% × 2.78% × 2.78%

The key word is independent.

If every Saturday you follow the same routine, leave at the same time, wait at the same traffic light, pass the same security gate, use the same elevator, and walk at the same speed, these events may not be independent. You may not be landing randomly inside a 600-second cycle. You may be landing near the same part of the cycle every time.

Then repeated catching or repeated near-missing is no longer just a probability problem. It means your travel routine has synchronized with the train schedule.

This explains a common feeling in daily life: some people always feel they are “just a little late.” Often, fate is not targeting you. Your routine simply puts you repeatedly inside the same bad window.

Why This Problem Is More Than Simple Probability

If the only question is “what fraction of 600 seconds is 30 seconds?”, then yes, the problem is extremely simple.

But modeling is not about making a problem unnecessarily complex. It is about stating boundaries clearly. This example has at least three layers.

The first layer is the time-window model. It only uses headway and dwell time, producing 5% and 2.78%. This is the final answer used in this article because it strictly relies on the given conditions.

The second layer is the time-plus-distance model. It introduces passenger distance X and turns “catching the train” into:

X <= v × remaining open-door time

This layer requires a distance distribution and therefore may require integration.

The third layer is the behavior model. Real people do not arrive uniformly at random. Some check real-time arrival information, some leave at fixed times, and some are interrupted at ticket gates, elevators, or escalators. Four consecutive catches or four consecutive unlucky near-misses often mean the travel rhythm and train schedule have formed a stable relationship, not that each trip is independent and random.

So the arithmetic is not hard. The difficult part is not telling the model incorrectly. A simple model gives a clear answer. A complex model tells us what data is missing.

Verifying With Python

The minimal model can be checked with a few lines of Python:

interval = 10 * 60
stop_time = 30
speed = 3
unlucky_distance = 50

catch_probability = stop_time / interval
four_catches = catch_probability ** 4

unlucky_window = unlucky_distance / speed
unlucky_probability = unlucky_window / interval
four_unlucky = unlucky_probability ** 4

print(catch_probability, four_catches)
print(unlucky_probability, four_unlucky)

The output corresponds to:

0.05 0.00000625
0.027777777777777776 0.0000005954...

As percentages:

EventDecimalPercentAbout
Catch once0.055%1 / 20
Catch 4 times in a row0.000006250.000625%1 / 160000
Very unlucky once0.02777782.78%1 / 36
Very unlucky 4 times in a row0.0000005950.0000595%1 / 1679616

How to Use the Result

The probability of catching the train once is 5%. If you arrive completely randomly, you should not expect luck to place you inside the open-door window.

The probability of being very unlucky once is 2.78%. So arriving right after the doors close is not rare. If you take the subway often enough, it will happen.

Catching it four times in a row is about one in 160,000. Being very unlucky four times in a row is about one in 1.68 million. If such a repeated event really happens, it more likely means your departure rhythm is not random. It is consistently aligned with the train schedule in an unfortunate way.

So the practical advice is not “pray for better luck.” Move the whole departure time forward by one or two minutes.

For a subway line with a 10-minute headway, leaving two minutes earlier is not a small adjustment. It moves you out of a narrow unlucky window and into a much wider safe zone. After all the probability work, the conclusion is very ordinary: do not cut it that close.