Railroad Bridge

A man needs to go through a train tunnel. He starts through the tunnel and when he gets 1/4 the way through the tunnel, he hears the train whistle behind him. you don’t know how far away the train is, or how fast it is going, (or how fast he is going).  All you know is:

  1. if the man turns around and runs back the way he came, he will just barely make it out of the tunnel alive before the train hits him.
  2. if the man keeps running through the tunnel, he will also just barely make it out of the tunnel alive before the train hits him.

Assume the man runs the same speed whether he goes back to the start or continues on through the tunnel.  Also assume that he accelerates to his top speed instantaneously.  Assume the train misses him by an infintisimal amount and all those other reasonable assumptions that go along with puzzles like this so that some wanker doesn’t say the problem isn’t well defined.

How fast is the train going compared to the man?

Solution

I haven’t written up a solution for this yet, but smarter people than I have described some on the discussion forum. You can read their thoughts here.

2026 Update: The Train Bridge Puzzle — Relative Motion and Linear Equations

Classic version: A man walks across a railroad bridge. When he’s 1/4 of the way across, he hears a train behind him. If he runs back, the train hits him exactly at the start. If he runs forward, the train hits him exactly at the end. How fast is the train relative to the man?

Solution: Let bridge length = 4d, man’s position = d from start. Train speed = 4× man’s speed.

def solve_railroad_bridge():
    """
    Let:
    - Bridge length = L (normalized to 4)
    - Man's position from start = x (normalized to 1, so x/L = 1/4)
    - Man's speed = 1 (unit)
    - Train's speed = v (unknown)
    - Train's distance from bridge start = D (unknown)

    Case 1: Man runs BACK (distance = x = 1)
    Train covers D in same time man covers x=1.
    → D / v = 1 / 1 → D = v

    Case 2: Man runs FORWARD (distance = L-x = 3)
    Train covers D+L in same time man covers 3.
    → (D + L) / v = 3 / 1 → D + 4 = 3v

    From D = v and D + 4 = 3v:
    v + 4 = 3v → v = 2 (train is 2x man's speed)
    D = 2 (train is 2 bridge-lengths away)
    """
    from sympy import symbols, solve, Eq

    v, D = symbols('v D', positive=True)
    L = 4  # Normalized bridge length
    x = 1  # Man's position (1/4 of bridge)

    # Case 1: Run back
    eq1 = Eq(D / v, x / 1)  # Time for train = time for man

    # Case 2: Run forward
    eq2 = Eq((D + L) / v, (L - x) / 1)

    solution = solve([eq1, eq2], [v, D])
    return solution

result = solve_railroad_bridge()
print(f"Train speed: {result[symbols('v')]}x man's speed")  # 2x
print(f"Train distance from bridge: {result[symbols('D')]} bridge-lengths")  # 2

# Verify simulation
def simulate_bridge(bridge_len=4.0, man_pos=1.0, man_speed=1.0, train_speed=2.0, train_dist=2.0, dt=0.001):
    # Case 1: man runs back
    man = man_pos
    train = -train_dist  # Train position (bridge starts at 0)
    t = 0
    while man > 0 and train < 0:
        man -= man_speed * dt
        train += train_speed * dt
        t += dt
    print(f"Case 1 (run back): man at {man:.3f}, train at {train:.3f}, t={t:.3f}")

    # Case 2: man runs forward
    man = man_pos
    train = -train_dist
    while man < bridge_len and train < bridge_len:
        man += man_speed * dt
        train += train_speed * dt
    print(f"Case 2 (run forward): man at {man:.3f}, train at {train:.3f}")

simulate_bridge()

Why this puzzle appears in interviews: It tests whether you can set up simultaneous equations from word problems — a fundamental skill in algorithm analysis, distributed systems timing problems, and any problem requiring rate × time = distance reasoning. The key is identifying what’s constant (time) across both scenarios.

Scroll to Top