Ants on a Stick
Ants march along a stick and turn round whenever they meet. How long until every ant has fallen off? One idea makes it easy.
Press Play. Click the stick to add an ant; click an ant to turn it round, click again to remove it.
What’s going on
A stick is 60 cm long. Some ants sit on it, each facing left or right, and they all walk at 1 cm per second. When two ants meet head-on, both turn round. When an ant reaches an end, it falls off.
Press Play in the scene above. The diagram under the stick records the ants’ paths: position across, time downwards. The amber ant’s path is a zigzag, and it is hard to guess when it will fall. Yet the whole stick is empty after 54 seconds, and you can find that number in your head.
The ghost trick
From a distance, ants look exactly alike. Now watch a meeting. Two ants walk towards each other, touch, and walk apart. If they had simply walked through each other, you would see exactly the same thing: one ant going left, one going right, from the same point at the same moment. Only the names would be different.
Press Ghost view. The labels now stay with “ghost” ants that never turn round. The dots on the stick and the lines in the diagram are exactly the same as before. Only the colours of the lines have moved.
That makes the question simple:
- A ghost walks straight to the end it faces, so it leaves after (distance to that end) seconds.
- The stick is empty when the last ghost leaves. So the answer is the longest single walk.
In the starting picture, ant A sits 6 cm from the left end and walks right, so its walk is 60 − 6 = 54 cm. No other walk is longer, so the last ant falls at 54 seconds. Press Show longest walk to see it.
Notice that the ant who actually falls last is D, not A. The trick gives the time, not the name of the last ant. There is a second consequence: since no walk is longer than the stick, every ant is gone within one minute, however many ants there are and however they face.
Which ant is which?
Real ants never overtake each other, because they turn round instead. So the real ants keep their order along the stick. That gives a neat way to find any real ant at any time: work out where all the ghosts are, sort those places from left to right, and hand them to the real ants in their starting order. The scene draws the ants exactly like this.
Counting bounces
The trick also counts meetings. Two real ants meet exactly when two ghosts cross. A right-walking ghost crosses every left-walking ghost that starts ahead of it, once, and no other ghost. In the starting picture there are 7 such pairs, so 7 bounces. Press 10 against 10 to try a famous version.
A ring
Switch Track to Ring. Now there are no ends, and the ants bounce for ever. After one full lap, 60 seconds, every ghost is back on its own starting spot, so every starting spot is filled again. But the real ants have shifted along. With 4 ants walking clockwise and 3 anticlockwise, each ant ends up exactly where its neighbour began.
Try it yourself
1. Ten against ten
Ten identical balls roll to the right along a line, and ten more roll towards them from the right, all at the same speed. When two balls collide, they bounce back at the same speed. How many collisions happen in all?
Answer
A hundred. Pretend that colliding balls pass through each other: the picture does not change. Then each ball rolling right meets each ball rolling left exactly once, and there are 10 × 10 such pairs. Check it with the 10 against 10 button.2. Stay as long as possible
You may place as many ants as you like, facing any way. How long can you keep at least one ant on the stick?
Answer
Just under a minute, never a full minute or more. Each ghost leaves after at most 60 seconds, because no walk is longer than the stick. To get close to 60 seconds, put an ant very near one end, facing the other end.3. A lap of the ring
A ring is 60 cm round. Ants stand at 10, 25, 40 and 50 cm. The first three walk clockwise, the last one walks anticlockwise. After one minute, where is the ant that started at 10 cm?
Answer
At 40 cm. After a lap the ghosts are back on the four starting spots, so the real ants are too, still in the same order round the ring. Bounces only swap speeds, so together the real ants travel as far as the ghosts: 3 laps clockwise minus 1 lap back, a net 2 laps. Shared out in order, that moves every ant 2 places along: 10 to 40, 25 to 50, 40 to 10 and 50 to 25.Go deeper
- Two equal balls that collide head-on, with no energy lost, swap their speeds. That is why the ghost trick works for them too, and why physicists can treat identical particles on a line as if they passed through each other.
- The ant puzzle is a favourite in mathematics olympiads and programming contests, because a frightening simulation turns into a single line of thinking.
Inspired by the article «Муравьи на палке» by M. Prasolov in Kvantik magazine, February 2014. The text, code and pictures on this page are our own.
Comments
No comments yet. Be the first to share what you noticed.