# Two Trains, One Track

Two trains are heading towards each other on a track. One train is blue, the other is green. Each train has a locomotive hauling nine wagons.

Each locomotive is 10 meters long, and each wagon is also 10 meters long.

Between the trains, there is a small area with a parallel 40 meters track accessible via switches. The tracks between the switches can therefore accommodate four wagons, or one locomotive and three wagons, or two locomotives and two wagons.

Something like this (B=Blue, G=Green, W=Wagon, L=Locomotive):

INITIAL SETUP
/------------\
--------BW-BW-BW-BW-BW-BW-BW-BW-BW-BL----<              >----GL-GW-GW-GW-GW-GW-GW-GW-GW-GW-------
\------------/

Locomotives can haul (pull) and shove (push) any or all of the other rail vehicles (i.e. wagons and/or the other locomotive), in both directions. Rail vehicles can be attached and detached. For example, one could detach the last five wagons, and let a locomotive only haul four wagons.

The goal is to get the trains past each other, with each locomotive hauling its original nine wagons (not necessarily in the original order for the wagons, but the locomotive should be at the front of the train):

THE GOAL
/------------\
------GL-GW-GW-GW-GW-GW-GW-GW-GW-GW------<              >----BW-BW-BW-BW-BW-BW-BW-BW-BW-BL-------
\------------/

Attach and detach rail vehicles and make use of the 40 meters parallel track to achieve this.

For example, one could start with the original setup (this is just to demonstrate some possible actions, not the actual solution):

INITIAL SETUP
/------------\
--------BW-BW-BW-BW-BW-BW-BW-BW-BW-BL----<              >----GL-GW-GW-GW-GW-GW-GW-GW-GW-GW-------
\------------/

Then detach the third wagon from the green train and bring the green locomotive and its first two wagon on a track between the switches:

STEP 1
/--GL-GW-GW--\
--------BW-BW-BW-BW-BW-BW-BW-BW-BW-BL----<              >-------------GW-GW-GW-GW-GW-GW-GW-------
\------------/

Then detach the last blue wagon and take the blue locomotive and its first eight wagons to the other side, potentially shoving the green wagons along:

STEP 2
/--GL-GW-GW--\
--------BW-----<              >------------BW-BW-BW-BW-BW-BW-BW-BW-BL-GW-GW-GW-GW-GW-GW-GW-------
\------------/

Then detach the last wagon connected to the green locomotive and leave it on the side track, while the green locomotive is moving forward, shoving the blue wagon:

STEP 3
/--------GW--\
---BW-GL-GW----<              >------------BW-BW-BW-BW-BW-BW-BW-BW-BL-GW-GW-GW-GW-GW-GW-GW-------
\------------/

Then attach the green wagon to the blue locomotive and move the blue locomotive backwards, on the lower track, and on to the other side, and stop somewhere:

STEP 4
/--------GW--\
---BW-GL-GW-BW-BW-BW-BW-BW-BW-<              >-GW-GW-GW-GW-GW-GW-------
\-BW-BW-BL-GW-/

And so on.

Attach, detach, haul, shove, use the parallel tracks to get the trains past each other.

Source: this is from the game Puzzillion, though I believe I saw this puzzle somewhere else many years ago, but I cannot find it anywhere else now.

• Railroad Shunting Puzzle 2 was a popular Flash game ten or twelve years ago. It is unfortunately among those that are not supported by current Flash emulators. Nov 14, 2023 at 1:25
• I don't remember whether this exact puzzle was there, but I've definitely seen at least one and probably more train puzzles kind of like this in Boris Kordemsky's wonderful puzzle book The Moscow Puzzles: 359 Mathematical Recreations. Nov 14, 2023 at 8:25
• Each locomotive is capable of pushing/ pulling up to all 18 wagons at once if need be? Nov 14, 2023 at 10:04
• Yes, each locomotive can push and pull all wagons and the other locomotive if needed. Updated description to clarify.
– Gec
Nov 14, 2023 at 13:00
• I'm getting real Towers of Hanoi flashbacks... Nov 14, 2023 at 18:46

Not sure if it's optimal, but here's a solution:

1. The BL pulls 3 BW and parks in the top track.

2. The entire green train passes underneath to the left.

3. Now the BL+3BW can move to the right.

4. Next, the entire green train + 3 BW move to the right via the top track

5. halfway, the blue wagons are decoupled and left on the top track

6. The entire green train continues a bit and returns via the bottom track to the left

7. Now the partial blue train from the right can fetch the extra 3 wagons and pull them to the right

8. Repeat steps 4..7

Note that the same number of steps would work with larger trains:

One train (eg. green) could have been arbitrarily long (as long as there's enough space on either side of the double rail. While the blue train could have had 2 extra wagons (using an extra wagon in step 4)

• Wow that was fast :). There are other solutions too, not sure what the optimal one is, but yours works.
– Gec
Nov 13, 2023 at 22:23

Maybe this deserves a separate question, but… imagine the GL broke down. It can still be towed by BL. Otherwise same assignment. Is it possible?

Yes.

Without ever disconnecting, the entire blue train goes right to fetch 4 green pieces (GL+3GW), pull back and leave those disconnected onto the top track, drive via the bottom track to the right so that it can push those 4 green pieces all the way to the left.

Repeat two more times.

• Blue could even push green all the way to the next station :)
– Gec
Nov 15, 2023 at 8:21