Two Trains, One Track

  • Medium
  • River crossing puzzles
  • Tests: Using a dead end as temporary storage

The puzzle

Two locomotives meet head on along a single track. Part-way along is a short siding - a dead-end spur - long enough to hold exactly one locomotive and nothing more.

How do they pass, and in how few moves? Then say what changes if each engine is pulling two carriages.

Stuck?

One at a time, smallest first. Open only as many as you need — the whole point of the puzzle is the part you work out yourself.

Hint 1

A siding does not have to be somewhere you leave something permanently.

Hint 2

Only one engine needs to get out of the way at a time.

Show the answer Hide the answer

Three moves: the eastbound engine pulls into the siding, the westbound engine runs past, the eastbound engine comes out and carries on. With carriages it takes many more moves, and if the siding holds fewer vehicles than a whole train it may be impossible.

How to get there

Move one: train A runs into the siding and stops. The main line is now clear through the junction. Move two: train B runs west past the siding and continues on its way. Move three: A reverses out of the siding and resumes eastward. Three moves, and the siding was occupied for only one of them.

With carriages the problem changes completely. A siding holding one engine and one carriage cannot hold a whole train, so a train must be split, parts shuffled past one another, and recombined - which takes a long sequence of couplings and reversals rather than three moves.

And it can become impossible. If the siding holds fewer vehicles than the shorter train has, there is no way to get an entire train out of the way at once, and whether a passing manoeuvre exists depends on exactly how the carriages may be split and recoupled.

The technique worth keeping

A dead end is storage, not a route. Ask what has to be out of the way and for how long, rather than how everything can be arranged at once - and check whether the storage is large enough for the smallest indivisible unit.