PuzzleReels
Sections

The Bridge at Night

The maths · Episode 24 · 2:53 · gives the answer

The puzzle

Four people stand at one end of a rope bridge at night. Alone, they take 1, 2, 5, 10 minutes to cross. The bridge holds at most two at a time. There is one torch, and nobody may cross without it, so someone must carry it back for the next crossing. Two people crossing together go at the pace of the slower one. What is the least total time for all four to get across?

The maths, properly

Write the four times a≤b≤c≤d, which for the film are 1, 2, 5, 10. A move is one crossing: one person or two, going over with the torch or coming back with it. A move costs the time of its slowest walker, and the clock is the sum.

Route one: the escort

The natural plan is to let the fastest walker, 1, take everybody over, one at a time, and walk the torch back each time:

movewhocostclock
over1, 222
back113
over1, 558
back119
over1, 101019

That is 19 minutes. It is the plan most people find first. The film also tries others, of 21, 25 and 23 minutes, which are all slower. In the escort plan the 5 and the 10 cross in separate moves, so they cost 15 minutes between them, out of the 19.

The script checks that 19 is the best possible for any plan in which the 5 and the 10 never cross together. It does so by searching every plan of that kind.

Route two: pair the slow ones

The 5 and the 10 are the expensive ones. Crossing together costs 10, the pace of the slower, not 5+10. The pair rides for the price of one. But the torch then has to come back, and neither of them should carry it, since walking back costs at least 5. So a fast walker must already be on the far side. That is why the first move sends the two fast walkers over:

movewhocostclock
over1, 222
back113
over5, 101013
back2215
over1, 2217

That is 17 minutes. The other plan of the same length has the 2 walking back first and the 1 later:

movewhocostclock
over1, 222
back224
over5, 101014
back1115
over1, 2217

Where the two minutes come from

Split each plan into the time spent going over and the time spent coming back.

plangoing overcoming backtotal
escort17219
pair14317

The pairing plan spends more on coming back, 3 against 2, because the 2 walks back instead of the 1. It saves more on the way over, 14 against 17, because the 5 crosses for free. The saving is larger than the cost, and the difference is 19 − 17 = 2 minutes.

In letters, the escort plan costs 2a+b+c+d and the pairing plan costs a+3b+d. The difference is

(2a+b+c+d)−(a+3b+d)=a+c−2b

For the film that is 1+5−4=2. Pairing is better exactly when this is positive, which is 2b<a+c.

Is 17 really the best?

A hand proof has to rule out every strange plan, such as three people on the far side and one coming back and forth. The script does that by brute force. It lists every reachable position, that is who is on which bank and where the torch is, finds that there are 30 of them, and then follows every route that never repeats a position. There are 73,644 such routes, and the cheapest costs 17. No route costs 18 and none costs 22. That is a proof by exhaustion, and it settles the film's four times.

What the brute force does not do is say why. The reason is in the two plans. The ordinary moves are needed whatever happens: at least three crossings carry someone over and at least two bring the torch back. The only decision is whether the two slowest walkers share a crossing. If they do, only one of them is paid for, and the torch must be fetched by a fast walker. If they do not, both are paid for. The rule above weighs the two.

What changes if the numbers change

The film's times are special. Change them and the better plan changes.

timesescortpairbestbetter plan
1, 2, 5, 10191717pair
1, 2, 3, 4111111tie
1, 5, 5, 10222622escort
1, 2, 3, 10171717tie

With 1, 5, 5, 10 the escort plan wins, because the second walker is slow too: in the pairing plan the 5 has to walk the torch back, and that costs more than it saves. The rule 2b against a+c says exactly this: here 10 against 6. For the other three rows, 2b against a+c is 4 against 6, 4 against 4 and 4 against 4, which gives a pairing win and two ties.

The script checks the formula over every sorted set of four times from 1 to 12, which is 1365 sets, by comparing it with a shortest-path search (Dijkstra's algorithm) over the positions. The two agree in every case: the pairing plan is strictly best in 581, the two tie in 203 and the escort plan is strictly best in 581.

Checking it

scripts/bridge.mjs asserts the claims below before it writes maths.json, and its --check fails if the file is stale. It checks that:

  • the 30 positions and 73,644 routes are as counted, the cheapest route costs 17, and exactly two plans reach it;
  • no plan costs 18 or 22;
  • the escort plan is legal and costs 19, and no plan in which 5 and 10 never cross together does better;
  • every plan in the film's montage is a legal sequence of crossings, with the totals 21, 19, 25, 23 and 17 that the film shows;
  • the two plans of 17 minutes are legal and their clocks are the ones above;
  • the ledger of over and back times adds up;
  • for all 1365 sets of times, the formula gives the same best time as the shortest-path search.

Where this shows up

  • Moving a group with a limited resource. Whenever one scarce thing (a torch, a boat, a bridge's capacity) must travel back and forth, the cost is not only the crossing but the return. The plan wins by putting the cheap return in the right place.
  • Shortest path in a state graph. The method the script uses is the one behind route-finding: treat each situation as a point, each legal move as a line with a cost, and ask for the cheapest way from the start to the goal.
  • A famous puzzle with many forms. It is usually told with the times 1, 2, 5, 10 and is attributed to no one in particular. With more than four people the best plan is found by repeating the same idea, and the escort and pairing moves are combined.

Try it yourself

1. What is the best time for walkers of 1, 3, 4 and 9 minutes?

Escort: 2a+b+c+d=2+3+4+9=18. Pairing: a+3b+d=1+9+9=19. So the escort plan wins here, and the best is 18. The rule agrees: 2b=6 is more than a+c=5.

2. Why does the pairing plan send the 1 and the 2 over first?

The 5 and the 10 cross together, and the torch must then come back. Whoever carries it back pays their own time again, so it should be a fast walker, and a fast walker has to be on the far side already. Sending the 1 and the 2 first puts one there.

3. In the ledger, the pair plan spends 3 coming back and the escort plan 2. How is the pair plan faster?

It saves more going over. With the 5 and the 10 together, the three trips over cost 14 instead of 17, a saving of 3, and the extra return costs 1. A saving of 3 for a cost of 1 is a net of 2.