PuzzleReels
Sections

The Nine Balls

The maths · Episode 23 · 2:45 · gives the answer

The puzzle

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.

The maths, properly

Number the balls 0 to 8. 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.

Route one: halve it

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:

weighingleft panright panasideanswer
10, 1, 2, 34, 5, 6, 78L
20, 12, 3noneR
323noneL

After the first weighing the left pan is down, so the heavy ball is among 0 to 3. After the second, the right pan of that weighing, balls 2 and 3, is down. In the third, ball 2 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.

Route two: thirds

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 ballfirst weighingsecond weighingfound
0LL0
3RL3
6EL6

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.

Why only three against three

A first weighing puts a balls against a balls, with 9−2a aside. After it, the worst case leaves max(a,9−2a) suspects, and with one weighing left you can handle at most three. That is the whole requirement, and it holds only for a=3. The script tries each:

balls per pansuspects if a pan goes downsuspects if levelweighings needed in the worst case
1173
2253
3332
4413

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 a=4, 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.

The general law

An upper bound. One weighing has three answers, so it separates at most 3 suspects. After the first weighing of a k-weighing plan, each of the three answers leaves a problem with k−1 weighings, which by induction handles at most 3k−1 suspects. So k weighings handle at most 3×3k−1=3k.

It is reached. Split 3k balls into three equal piles of 3k−1. Weigh two piles against each other. A pan down leaves its pile; level leaves the pile aside. Every answer leaves exactly 3k−1 suspects, and the same plan works on that pile. The script checks the largest number of balls that k weighings can handle:

weighingsmost balls
13
29
327
481

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 n≤3k. When n 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 n from 1 to 200 that the fewest weighings needed is exactly ⌈log3n⌉.

Checking it

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:

  • halving, four against four with one aside, finds every one of the 9 balls in at most 3 weighings, the aside ball in one, and fails to guarantee an answer in two;
  • thirds, three against three with three aside and then one against one, finds every ball in 2 weighings, with the nine runs giving nine different answer pairs;
  • of the first weighings a against a for a from 1 to 4, only a=3 works in two weighings;
  • the dynamic programme over 1 to 200 balls gives ⌈log3n⌉ for each n, with 9 balls needing 2, 10 balls needing 3 and 27 needing 3;
  • the explicit plan for 27 balls finds the heavy one in three weighings, for every position.

The script does not prove the upper bound for general k. That is the argument above, and it is short enough to check by hand.

Where this shows up

  • Information. Each weighing gives at most log23 bits, so k weighings give at most klog23 bits, and finding one of n balls takes log2n of them. The bound is the same counting argument, written in logarithms.
  • Ternary search. The plan is a search that splits the possibilities into three equal parts at each step. For comparisons that can only say "less, more or equal", that is the best you can do.
  • The harder puzzle. The classic version has twelve balls, one of them heavier or lighter and you don't know which, and three weighings. It is the same counting, with an extra unknown to account for.

Try it yourself

1. What is the most balls you can search with four weighings?

Four weighings give 34=81 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.

2. You have ten balls and two weighings. Why is it impossible?

Two weighings have 3×3=9 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.

3. Halving uses a first weighing of four against four. What does a level pan tell you there?

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.