Quant Memo
Core

Ants on a Pole and Collision Arguments

When two colliding objects bounce back exactly as if they had passed through each other, relabelling the ants makes the "impossible to track" collision problem trivial.

Prerequisites: How to Attack a Brainteaser

This puzzle sounds like it needs you to track every individual ant through a cascade of collisions, which seems combinatorially awful for more than two or three ants. The trick is realising you never need to track individuals at all — only the set of positions.

The puzzle

nn ants are placed at arbitrary points on a pole of length LL, each facing left or right. All ants walk at the same constant speed, 1 unit per second. When two ants collide, they instantly reverse direction (both bounce back the way they came) and keep walking. An ant that reaches either end of the pole falls off. What is the maximum possible time before all ants have fallen off, and how do you find it without tracking every collision?

The obstacle. With nn ants bouncing off each other unpredictably, simulating the collisions to find the last one to fall off looks like it requires case-by-case tracking of a combinatorial explosion of collision orders.

The reframe: ants are interchangeable. When two ants collide and both reverse, look only at the set of positions and directions over time, not at which named ant is where. Two ants approaching each other, colliding, and bouncing apart produce exactly the same picture — as a set of moving points — as two ants that walked straight through each other without interacting at all, just swapping which "name" is attached to which trajectory.

Why this solves it. Because collisions don't change the set of positions-over-time, you can analyse the much easier "ghost" system where ants pass through each other freely, ignoring collisions entirely. In that system, each ant simply walks straight to whichever end it was originally facing, taking at most LL seconds (an ant starting at position 0 facing right, or position LL facing left, takes the full LL seconds). So the last ant falls off at time at most LL, and this bound is achieved (e.g., a single ant starting at one end and walking the full length). The maximum time, over all starting configurations and directions, is exactly LL seconds.

real: ants collide and reverse collide here, both reverse ghost: same points, pass through, swap labels identical positions at every instant — only the labels differ
Bounce-and-reverse and pass-through-and-relabel produce the same set of moving dots, so the easier ghost model answers every question about positions and timing.

When two colliding, identical objects reverse on contact, the trajectory set is unchanged if you instead let them pass through each other and swap labels. Reframe collisions as label swaps in a label-free system and the problem usually collapses to single-particle reasoning.

This trick specifically needs the objects to be identical (same speed, indistinguishable once you stop tracking names) and the collision to be a clean, instantaneous reversal. If ants had different speeds, the pass-through trick would break.

Relabelling to strip out unhelpful bookkeeping is a broader habit: in a limit order book, tracking which specific resting order gets matched is often irrelevant to price and volume dynamics — what matters is the aggregate queue, exactly as only the set of ant positions mattered here, not which ant was which.

Related concepts

Practice in interviews

Further reading

  • Winkler, Mathematical Puzzles: A Connoisseur's Collection
ShareTwitterLinkedIn