PuzzleReels
Sections

The Fly Between Two Trains

The maths · Episode 19 · 2:15 · gives the answer

The puzzle

Two trains, 100 km apart, head straight at each other at 50 km/h each, so they close at 100 km/h. A fly sits on the nose of the left train. It flies at 150 km/h to the other train, touches the nose, turns round at once, flies back, and keeps going until the trains meet.

The statement has to be exact on three points, and the film says all three: the fly never rests, it turns round instantly, and it always flies at 150 km/h.

How far does the fly fly before the trains meet?

The maths, properly

Write L for the distance between the trains, vA and vB for their speeds, and f for the fly's speed. The fly is faster than both trains, f>vA and f>vB. That is needed for the legs to exist. A leg towards the right-hand train ends before the trains meet only if f>vA, because the time it takes is Lf+vB and the trains meet after LvA+vB. The leg back needs f>vB.

Route one: add up the legs

This is the film's first route. Take the case the film uses, where the two trains go at the same speed v. Say the gap between the noses is g and the fly is about to fly at the right-hand train.

The fly and that nose close on each other at f+v, so the leg takes gf+v hours, and the fly covers

leg=f·gf+v=ff+vg

For the film that fraction is 150200=0.75, three quarters of the gap.

In the same time the two trains close 2v per hour over gf+v hours, so the gap after the leg is

g(1−2vf+v)=f−vf+vg

For the film that ratio is 150−50200=0.5: each new gap is half the one before. The fly now stands on the right-hand nose and flies back, and by symmetry the same two facts hold for every leg, in either direction.

So the legs form a geometric series. The first leg is a=ff+vL and each is the fraction ρ=f−vf+v of the one before. Because 0≤ρ<1, the partial sums are a1−ρn1−ρ and they converge to

a1−ρ=ff+vL·f+v2v=fL2v

since 1−ρ=2vf+v. With the film's numbers the first leg is 75 km and the ratio is 0.5, so the sum is 75 / (1 - 1/2) = 150 km, and 2v is the combined speed of the trains: this is the claim.

Route two: look at the clock

This is the film's second route. The trains are 100 km apart and close at 50 + 50 = 100 km/h, so they meet after exactly 1 hour, at 50 km from either start. The fly never rests, so it flies for that whole hour at 150 km/h:

f·LvA+vB=150×1=150 km

Nothing about the bounces enters: not how many, nor how long, nor where.

Why they are one fact, for any speeds

The two routes are not two calculations that happen to agree. Each leg has a duration Δt, and during it two things happen: the fly flies fΔt, and the trains close the gap by (vA+vB)Δt. Add up the first n legs and let tn be the time they took. Then

flown after n legs=ftngap after n legs=L−(vA+vB)tn

The first line says the fly's distance is always its speed times the time it has been flying. That is the clock route, written at every stage and not only at the end. The second line says the gap is the original gap minus what the trains have closed. Now the gap goes to nothing, because over every pair of legs it is multiplied by a number below one (see "Different speeds for the two trains" below for the factors), so tn→LvA+vB and the distance flown goes to fLvA+vB. The series and the clock are the same limit.

For the film, tn=1−2−n and the gap after n legs is 1002n km, so the distance flown after n legs is 150(1−2−n) and it never quite reaches 150 in any finite number of legs.

Infinitely many legs in one hour

There is a leg for every n, and yet the whole flight lasts an hour. The legs take 12,14,18,… hours, and a list of positive times can add up to a finite number if it shrinks fast enough: 12+14+…=1, from below, with 2−n left over after n terms. This is the old puzzle of Zeno, in which the runner must first cover half the distance and then half of what is left, and the resolution is that infinitely many steps may have a finite total.

So the fly turns infinitely often before the hour is up, and there is no "last leg" and no time after the hour in which anything remains to be done. In the model the fly is a point, it turns without taking any time, and at the end of the hour the fly and both noses are at the same place, 50 km. The question the puzzle asks (how far before the trains meet) is answered by the limit.

A worked case: the film's legs

The film's first eight legs, with the fly flying right on odd legs and left on even legs. The fly ends each leg on a nose, and the last column is where.

LegGapTime (h)Fly fliesTotal so farGap afterFly ends at
11001/275755075
2501/437.5112.52537.5
3251/818.75131.2512.556.25
412.51/169.375140.6256.2546.875
56.251/324.6875145.31253.12551.5625
63.1251/642.34375147.656251.562549.21875
71.56251/1281.171875148.8281250.7812550.390625
80.781251/2560.5859375149.41406250.39062549.8046875

Every leg closes at 200 km/h, the fly's 150 plus the oncoming train's 50, so the time is the gap over 200. The fly's end points spiral in on the meeting point: each is half as far from 50 km as the one before, on the other side. The first leg ends at 75, 0.75 of the way along, and the next ends at 37.5, then 56.25.

The question beat freezes the film at 0.8 hours. Leg 3 began at 0.75 hours with the fly at 37.5 km, flying right at 150 km/h, so after a further 0.8 − 0.75 = 0.05 hours it is at 37.5 + 150 × 0.05 = 45 km. The trains are at 40 km and 60 km. The fly has flown 120 km so far, and the clock gets that without any legs at all: 150 × 0.8 = 120.

What changes if the puzzle changes

Different speeds for the two trains

Let the trains go at different speeds. The derivation of route one goes through for each leg separately. A leg towards the right-hand train multiplies the gap by f−vAf+vB, and a leg back towards the left-hand train by f−vBf+vA. These are different, so the legs no longer have a single ratio. They alternate: every second leg repeats the pattern, and the gap after every pair of legs is multiplied by

(f−vA)(f−vB)(f+vA)(f+vB)

which is below one, so the legs still run out. The series is now two interleaved geometric series, harder to sum and harder to see, but the argument of the previous section did not use equal speeds. The answer is still fLvA+vB.

The film uses 50 and 50 for exactly this reason. The story the puzzle is told with has 60 and 40 km/h, and the answer is the same 150 km. But the first leg is 100×150150+40 = 78.947 km, and the first four legs are 78.947, 33.835, 19.588, 8.395 km: not a tidy number, and no single ratio between them.

Other lengths and speeds

Everything scales. Double the distance and the answer doubles, since it is the fly's speed times the time the trains take. A faster fly flies further in the same hour. A slower fly (still faster than the trains) flies less in it. The answer depends on the fly's speed, the distance and the trains' combined speed, and not on how they share it.

Checking it

scripts/trains.mjs asserts the claims below, in exact fractions unless a float is the point, before it writes maths.json, and this page is built from that file.

  • The clock. 100 ÷ 100 is exactly 1 hour, at 50 km, and 150 × 1 is 150.
  • The legs. The shuttle is simulated leg by leg in exact arithmetic for a few dozen legs, as a table of gap, closing speed, time, length and gap after. Every figure is compared with the closed forms: the gap before leg k is 1002k−1, a leg is three quarters of its gap, and the next gap is half. The fly lands on the nose it was flying at each time. The ends spiral in on the meeting point as described.
  • The series. The partial sums are exactly 150(1−2−n) for every simulated leg. The sum 75 / (1 - 1/2) is 150. The identity that 1+12+… is 2−2−n after every term is checked term after term. The clock after n legs is 1−2−n hours.
  • The routes agree at every length. After every simulated leg, the distance flown is exactly 150 times the time taken, and the clock's answer and the series' sum are equal.
  • Two numerical runs. Event by event in floating point for 60 legs, where the flown distance, the time and the three positions all land on their limits, and in 100,000 small time steps with no formula for a leg at all, where the early turns land where and when the exact legs say.
  • Unequal speeds and random speeds. With 60 and 40, distance is always speed times time, the legs have no single ratio, but every second leg repeats it, and the answer is 150. The same for hundreds of seeded random speed sets, which also check that the distance flown plus what the fly would fly in the time left is always the clock's answer, and that summing legs in floating point does run out.
  • The question's frame. At 0.8 hours the fly is on leg 3 at 45 km between trains at 40 and 60, having flown 120 km.

What a script cannot do is add infinitely many legs. It checks a few dozen legs exactly and 60 in floats, and what makes the limit follow is the argument above: the gap after n legs is a known number that goes to nothing, and the distance flown is always ftn.

Where this shows up

  • Zeno's paradoxes. The runner who must cover half the remaining distance again and again is the same infinite list of times with a finite total. Here the legs are the steps and the hour is the sum.
  • Bouncing balls. In the idealised model, a ball that loses a fixed fraction of its speed at each bounce has infinitely many bounces in a finite time, for the same reason: the times between bounces are a geometric series.
  • Choosing the quantity to count. The legs are an awkward way into a problem in which the fly's speed never changes. Counting time, which is easy, and multiplying by the speed, is the trick the film is about.
  • A story that is told. The film ends on a story told about John von Neumann: put this puzzle, he answered at once, and when told he had spotted the trick, he replied that he had summed the series. It is a famous story and nobody here can vouch for the details. The maths does not depend on it.

Try it yourself

1. If the fly flew at 100 km/h instead of 150, how far would it fly?

The trains still meet after 1 hour, so it is 100 km/h × 1 hour = 100 km. In legs: ρ=100−50100+50=13 and the first leg is 100100+50×100=2003 km, so the sum is 200/31−1/3=100 km.

2. Now the trains are 200 km apart and still close at 100 km/h. What is the answer, and what changes in the table?

They meet after 2 hours and the fly flies 150 × 2 = 300 km. Every length in the table is doubled and every time is doubled too, as the first leg is ff+vL, which scales with L. The ratios, 0.75 and 0.5, do not change.

3. After how many legs are the trains less than a metre apart?

After n legs the gap is 1002n km. A metre is 0.001 km, so we need 2n>100000. Since 216=65536 is too small and 217=131072 is enough, it takes 17 legs. The time after 17 legs is 1−2−17 hours, a hair under the full hour, and the distance flown is within 150×2−17 km of 150.

4. Why does the fly's end point alternate either side of the meeting point?

Each leg ends on the nose it was flying at, and that nose has not yet reached the middle. The first leg ends at 75, which is 75 − 50 = 25 past the middle, and the second at 37.5, which is 12.5 short of it. The two noses are always level with each other about the middle, each half the gap away from 50 km. The fly lands on the right-hand nose, then the left, then the right, and the gap halves each time, so each end is half as far from the middle as the last, on the other side.