Math paradoxes

The bridge and the torch Four people, one torch, a narrow bridge. How many minutes to cross?17, not 19.

It is night. Four people must cross a narrow, shaky bridge. There is one torch, and nobody can step on the bridge without it. The bridge holds at most two. One person crosses in 1 minute, another in 2, the third in 5 and the fourth in 10. A pair walks together with the torch at the slower one's pace. The torch cannot be thrown across: someone has to carry it back. What is the fewest minutes for all four to reach the other side?

It looks as if the fastest should walk everyone over and bring the torch back each time: 10 + 1 + 5 + 1 + 2 = 19. But if the two slowest cross together, the 5 minutes of one hide inside the 10 minutes of the other. The price: an extra crossing by the pair 1 and 2 (2 minutes) and the 2 bringing the torch back instead of the 1 (1 more minute). 19 − 5 + 2 + 1 = 17.

Make a guess
17 minif 5 and 10 cross together
19 minif the fastest escorts everyone
108schedules of five crossings
The puzzle

Four people, one torch, a bridge for two

This puzzle is asked at job interviews to see how a candidate looks for the best plan rather than the first one that comes to mind. Behind it are shortest paths in a graph of states and a recurrence that Günter Rote proved in 2002.

  1. 1

    The bridge

    Narrow and shaky, it holds at most two people at a time. There is no other way to the far side.

  2. 2

    The torch

    There is one torch. Nobody can walk the bridge without it, so every crossing, there or back, is made by someone holding the torch. It cannot be thrown across.

  3. 3

    The speeds

    The four cross in 1, 2, 5 and 10 minutes. Two people walk together at the slower one's pace: the pair 2 and 10 takes 10 minutes.

  4. 4

    The question

    What is the fewest number of minutes in which all four can be on the far side?

Intuition says

"The fastest escorts everyone: 10 + 1 + 5 + 1 + 2 = 19 minutes"

The logic is clear: the fastest walker brings the torch back every time, so each return costs only a minute. But then 5 and 10 cross separately and occupy the bridge for 15 minutes between them. Send them together and you get 17.

Assumptions

  • At most two people on the bridge, and only with the torch.
  • A pair moves at the slower one's pace. Nobody carries anyone, and three cannot go at once.
  • The torch cannot be thrown, passed across the river or left on the bridge.
  • Only crossings take time. Handing over the torch on a bank is instant.
  • The torch lasts long enough, so there is no deadline: we look for the least time.
Round 1 · Guess

How many minutes until all four are across?

1, 2, 5 and 10 minutes, a bridge for two, one torch. Lock in the least time you think is possible.

20
1015202530

A breakdown of your answer will appear here.

Hints

Hard to decide? Open the hints one at a time: the easy one first, then stronger ones.

Round 2 · Game

Get everyone across, then try to break a rule

Click one or two people on the torch side and press "Cross". The clock counts the minutes. Then pick a rule in the right-hand card: the page goes through every set of times and looks for one where the rule loses to the best schedule.

Times, minutes
0

Break a rule

Rule
People

Round 3 · Exhaustive search and simulation

100,000 random crossings: which rule wins?

Each person crosses in a random whole number of minutes from 1 to 20, all equally likely. For each set the page finds the best schedule by a full search over states (Dijkstra's algorithm) and compares it with two simple rules. Bars show the exact shares, counted over every possible set; dots show the shares in the simulation.

People
the fastest escorts everyone the two slowest together neither rule

A rule counts as best if it reaches the optimal time. When both rules tie at the optimum, the set counts for both, so the shares can add up to more than 100%.

The fastest escorts everyone: best in
–
The two slowest together: best in
–
Neither rule is best
–
Rote's recurrence disagreed with the full search
–

Full search for your times from round 2

Round 4 · Five explanations

Why 17 and not 19

The whole difference is in who walks with the slow ones and who carries the torch back. Here are five ways to see it.

The two slowest

5 and 10 should share one trip

Separately10 + 5= 15 minutes on the bridge just for them
Together10minutes: the 5 hide inside the 10

A pair walks at the slower one's pace, so whoever walks with the 10-minute person rides for free, and it pays most when that companion is slow too. Putting the 1-minute walker next to the 10 wastes their speed. The most expensive thing in the puzzle is the slow walkers' minutes, and it pays to hide one inside the other.

The way back

The torch comes back twice

The fastest escorts1 + 1= 2 minutes on returns
The two slowest together1 + 2= 3 minutes on returns

At most two go over at a time, and one person brings the torch back. Each there-and-back pair of trips moves only one person net, so four people need at least three trips over and two back. Returns are unavoidable; the only question is who makes them. The 17-minute schedule pays one minute more on returns, but the way over costs 2 + 10 + 2 = 14 minutes instead of 10 + 5 + 2 = 17. In total 14 + 3 = 17 against 17 + 2 = 19.

Two shuttles

When the second fastest is fast enough

The fastest escorts everyone–
The two slowest together–

For four people the difference between the two plans is t₁ + t₃ − 2t₂. Sending the two slow ones together pays when the two "shuttles", the fastest and the second fastest, are quicker between them than the fastest and the third.

Every schedule

108 schedules, and only 2 give 17

A schedule of five crossings: a pair over (6 choices), one back (2), a pair over (3), one back (3), a pair over (1). In total 6 · 2 · 3 · 3 · 1 = 108. The page has just gone through all of them: the least time is 17 minutes, and only two schedules give it, differing in who comes back first, 1 or 2. Longer schedules, with seven or more crossings, are covered by the full search in round 3: none beats 17.

Sub-theory · shortest paths

Greedy choice versus the global optimum

d(v) = minu → v ( d(u) + w(u, v) )

A state of the crossing says who is on which bank and where the torch is: 2⁴ · 2 = 32 possibilities, of which 30 are reachable. A crossing with cost w links two states, and the puzzle becomes a shortest-path search in a graph. Dijkstra's algorithm settles states in order of increasing distance d and guarantees the optimum. The rule "the fastest escorts everyone" is greedy: it makes every return as cheap as possible but ignores what the way over will cost. The shortest path sometimes starts with a dearer step.

For formula lovers

Rote's recurrence: how to move n people

Sort the times. The two slowest are moved in one of two ways, and the problem shrinks by two people.

t1≤t2≤…≤tn T(n)=min(t1+2t2+tn,2t1+tn−1+tn)+T(n−2) T(3)=t1+t2+t3,T(2)=t2,T(1)=t1

The first term in the min: the two fastest act as shuttles and the two slowest go together. The second: the fastest escorts each of the two.

t1+2t2+tn:(1,2)→,1←,(n−1,n)→,2← 2t1+tn−1+tn:(1,n)→,1←,(1,n−1)→,1←

For 1, 2, 5, 10: first move 5 and 10, then 1 and 2 remain.

T=min(1+4+10,2+5+10)+2=15+2=17 Together is better if2t2<t1+tn−1:4<6

In 2002 Günter Rote proved that this recurrence always gives the optimum, for any number of people. The choice is made afresh at each step: with six people it can pay to send the two slowest together and then escort the next two one by one. The page checked the recurrence against a full search in round 3.

Round 5 · Scaling up

More people, a wider bridge, the slow ones in one batch

The bridge puzzle teaches a simple thing: it pays to group the expensive items together. In mathematics this is a recurrence for any number of people. In logic it is the gap between a locally sensible step and the best plan. In practice the same trick cuts computing time.

Mathematics

Your times, your bridge

Bridge holds
Best time–
Fastest escorts–
States settled–

n people and capacity 3

A recurrence for a bridge for two, a search for a wider one

For a bridge for two, Rote's recurrence works for any number of people: sort the times and keep moving the two slowest in the cheaper way. The table on the left shows every step. The count takes only a handful of operations even for a thousand people.

If the bridge holds three, no simple formula is in sight, and the page searches for the shortest path in the graph of states. For 1, 2, 5, 10 the answer is 13 minutes: 1, 5 and 10 go together (10), 1 comes back (1), 1 and 2 cross (2). Same idea: the slow walkers hide their minutes in one crossing.

Logic

Six people: 1, 3, 4, 5, 20, 20

First move the two 20-minute walkers, then 4 and 5, finally 1 and 3. Pick the method for each pair.

20 and 20
4 and 5
Total–

A local step and the whole plan

No fixed rule wins every time

Each of the two rules makes sense at its own step. "The fastest escorts" minimises the returns. "The two slowest together" minimises the way over. But the best plan here is mixed: the two 20-minute walkers should go together, while 4 and 5 are better escorted one by one. For six people with times from 1 to 20 this happens in about 29% of sets (round 3).

The general lesson: optimise the bottleneck. The most expensive minutes in this puzzle belong to the slowest walkers, and the plan should be built around them, not around whoever runs back and forth most conveniently. The same lesson appears in the poisoned wine puzzle: what matters is not each step but the whole scheme.

Practice

Batches of jobs: slow with slow

Eight jobs of 1, 2, 3, 4, 10, 11, 12, 13 minutes. A machine runs them in batches, and a batch lasts as long as its longest job. Batches run one after another.

Jobs per batch
Total time–
Best–

From the bridge to computing

Long jobs together, so the slow hides inside the slow

If a batch lasts as long as its longest job, putting a short job next to a long one wastes a slot: the short one waits anyway. Sort the jobs and cut them into consecutive batches from the longest: with batches of 2 this gives 13 + 11 + 4 + 2 = 30 minutes instead of 46 when every fast job is paired with a slow one. A search over all splits confirms that 30 is the best.

This is done when training neural networks: sentences of different lengths are padded to the longest in a batch, so they are grouped by length to keep short ones from waiting for long ones. The same goes for CI: long tests go into one run rather than being spread across all of them. The bridge has one more twist that batches lack: the torch must come back, which is why the two fast walkers become shuttles.

Bonus · Fun facts

Things to tell your friends

1981

The earliest known printing

The puzzle appears at least as early as 1981, in the book "Super Strategies for Puzzles and Games" by Saul Levmore and Elizabeth Cook. There four men in enemy territory cross a bridge over a ravine with a lantern: 5, 10, 20 and 25 minutes, one hour for all.

U2

A band on the bridge

The best-known interview version: the four members of U2 (1, 2, 5 and 10 minutes) must cross before the bridge collapses in 17 minutes. William Poundstone described it in 2003 in "How Would You Move Mount Fuji?", a book about puzzle interviews at Microsoft. The story that Microsoft gave it to every applicant goes back to a 1998 chain e-mail.

2002

The proof for n people

Günter Rote of the Free University of Berlin published "Crossing the bridge at night" in the Bulletin of the EATCS (volume 78, October 2002) and proved that the recurrence with two ways of moving the slowest pair is always optimal. Torsten Sillke had conjectured it, and a few months earlier the same bulletin had printed a paper by Cristian and Elena Calude with a wrong general answer.

108

Schedules of five crossings

Four people have exactly 108 schedules without wasted crossings. Only 2 of them take 17 minutes, 6 take 19, and the worst takes 50 minutes.

1959

Dijkstra's algorithm

Edsger Dijkstra published his shortest-path algorithm in 1959 in "A note on two problems in connexion with graphs" in Numerische Mathematik. It is what searches the states of the crossing in round 3.

C

A bridge for C people

In 2008 Roland Backhouse analysed the general case where the bridge holds C people, in "The capacity-C torch problem" at the Mathematics of Program Construction conference (Marseille).

Algorithmic Puzzles

Anany Levitin, Maria Levitin

2011 · puzzle 7

How Would You Move Mount Fuji?

William Poundstone

2003 · the U2 puzzle

All books →
Discussion

What do you think?

Share your own explanation, an objection or a variant of the puzzle. You need a GitHub account to comment.

Newsletter

New puzzles, explanations and discussions

I keep adding new puzzles, new ways to explain them and write-ups of the discussions they start. Leave your email and I'll write when something new is out. No spam, one-click unsubscribe.

The sign-up form will appear here soon.