9 balls look identical, and one of them is slightly heavier than the rest. You have a two-pan balance. It gives no weights: it says only that the left pan is down, the right pan is down, or that they are level. Each weighing must put the same number of balls on each pan. You may weigh 3 times. Find the heavy ball.
Number the balls to . A weighing puts some balls on the left, the same number on the right, and leaves the rest aside. If the heavy ball is on the left, the left pan goes down (L); if it is on the right, the right pan goes down (R); if it is aside, the pans are level (E). So each weighing has exactly three possible answers, and which one you get depends on where the heavy ball is.
Nine will not split in two, so leave one ball aside and weigh four against four. The three answers leave these numbers of suspects: 4, 1, 4. If the pans are level, the ball that was aside is the heavy one, found in one weighing. If a pan goes down, the heavy ball is among its four. Weigh two of them against the other two, then one against one. That is three weighings in all, and the script runs it for every one of the nine positions of the heavy ball: ball 8, the one aside, is found in 1 weighing and every other ball in 3.
As an example, the film's own run has the heavy ball at position 2:
| weighing | left pan | right pan | aside | answer |
|---|---|---|---|---|
| 1 | 0, 1, 2, 3 | 4, 5, 6, 7 | 8 | L |
| 2 | 0, 1 | 2, 3 | none | R |
| 3 | 2 | 3 | none | L |
After the first weighing the left pan is down, so the heavy ball is among to . After the second, the right pan of that weighing, balls and , is down. In the third, ball is on the left and the left is down, so it is the heavy one.
Why halving cannot do it in two. If the first weighing is four against four and one pan goes down, four suspects are left and a single weighing remains. A single weighing has three answers, so it can tell apart at most three suspects. Four is too many.
Halving leaves the third answer nearly unused. Level already means "the ball I left aside", and with one ball aside that is a poor use of an answer. Leave three aside instead and weigh three against three. The three answers now leave 3, 3, 3 suspects, an even split.
Now each of the three groups is the same small problem: three balls, one heavy, one weighing. Weigh one against one and leave the third aside. If a pan goes down, that ball is the heavy one. If they are level, it is the one aside. So two weighings suffice. The script runs it for all nine positions of the heavy ball, and every run takes 2 weighings. Here are three of them:
| heavy ball | first weighing | second weighing | found |
|---|---|---|---|
| 0 | L | L | 0 |
| 3 | R | L | 3 |
| 6 | E | L | 6 |
Read the answers as a two-letter word. There are nine heavy-ball positions and nine two-letter words from L, R and E, and the script checks that the nine runs give nine different words, so no two balls are ever confused and no word is wasted.
A first weighing puts balls against balls, with aside. After it, the worst case leaves suspects, and with one weighing left you can handle at most three. That is the whole requirement, and it holds only for . The script tries each:
| balls per pan | suspects if a pan goes down | suspects if level | weighings needed in the worst case |
|---|---|---|---|
| 1 | 1 | 7 | 3 |
| 2 | 2 | 5 | 3 |
| 3 | 3 | 3 | 2 |
| 4 | 4 | 1 | 3 |
Only the row with three per pan keeps both numbers at three or fewer, so only it finishes in two weighings in the worst case. The others leave four, five or seven suspects with one weighing to go.
A weighing cannot do more than , because the pans must hold equal numbers and there are only nine balls. This is the same count as the film's, seen from the other side.
An upper bound. One weighing has three answers, so it separates at most suspects. After the first weighing of a -weighing plan, each of the three answers leaves a problem with weighings, which by induction handles at most suspects. So weighings handle at most .
It is reached. Split balls into three equal piles of . Weigh two piles against each other. A pan down leaves its pile; level leaves the pile aside. Every answer leaves exactly suspects, and the same plan works on that pile. The script checks the largest number of balls that weighings can handle:
| weighings | most balls |
|---|---|
| 1 | 3 |
| 2 | 9 |
| 3 | 27 |
| 4 | 81 |
So nine balls fill two weighings exactly. A tenth ball has nowhere to go, and needs a third weighing. With three weighings the limit is 27.
Other numbers of balls. The bound says . When is not a power of three, you still split it as evenly as the pans allow, and the script checks by dynamic programming over every from 1 to 200 that the fewest weighings needed is exactly .
scripts/nine-balls.mjs asserts the claims below before it writes maths.json, and this page is built from that file. Its --check fails if the file is stale. It checks that:
The script does not prove the upper bound for general . That is the argument above, and it is short enough to check by hand.
Four weighings give balls. Split them into three piles of 27, weigh two against each other, and the heavy pile is then handled by the three-weighing plan.
Two weighings have possible pairs of answers, and the ten balls would need ten different pairs. Two balls would share a pair of answers, and the weighings could not tell them apart.
It tells you that the one ball left aside is the heavy one. That is one answer used up to name one ball, which is why halving wastes the third answer.