PuzzleReels
Sections

The King's Thousand Bottles

The maths · Episode 2 · gives the answer

The puzzle

A king has 1000 bottles of wine, and exactly one has been spiked with a sleeping draught that takes exactly an hour to act. He has 10 tasters, each of whom may drink one mixture of any bottles he likes, and one hour: time for a single round and no second.

How should they drink, so that whoever falls asleep tells him which bottle it was?

The maths, properly

Number the bottles 1 to 1000. A plan is a cup for each taster: the set of bottles poured into his mixture. An hour later a taster is asleep exactly when the spiked bottle was in his cup. So each bottle has its own pattern, the set of tasters whose cups it went into, and that pattern is what the king sees.

Route one: halve it, ten times, all at once

This is the film's first route. The cleanest way to see it is to count to 210=1024: lay out slots 0 to 1023, put the bottles in slots 1 to 1000, and leave the other 24 empty.

The first taster drinks from the upper half, slots 512 to 1023. Whether he sleeps says which half the bottle is in. The second taster drinks the upper half of each half, so whichever half it turns out to be, he splits it again. The third drinks the upper half of each quarter, and so on: taster k drinks the upper half of every block of width 1024/2k−1. After ten splits a block is one slot wide.

The halving looks as if it has to happen in turn, because the second question seems to depend on the first answer. It does not. The second taster's cup splits both halves at once, so it can be poured before anyone knows which half matters. Every cup is fixed in advance, all ten drink together, and the answers are read together at the end. For one bottle among many, asking all the questions up front costs nothing.

The film halves the 1000 itself, so its first taster drinks bottles 1 to 500. That works too: the halves have to be rounded, but ten rounded halvings still give every bottle its own pattern. Those cups are not the binary ones below, though: none of the ten matches a binary cup, or the reverse of one. The two routes give literally the same cups when the halving is done on the 1024 slots.

Route two: numbers on the tasters

Hang 1,2,4,…,512 on the tasters. Every whole number from 0 to 1023 is a sum of some of them in exactly one way, which is all that writing a number in binary means.

There is a one-line proof. Ten numbers have 210=1024 subsets, and every subset adds up to something from 0 to 1+2+⋯+512=1023. Two different subsets cannot give the same total: look at the biggest number in one and not the other, 2j. It outweighs all the smaller ones together, since 1+2+⋯+2j−1=2j−1. So 1024 subsets land on 1024 totals, one each.

Taster k, wearing 2k−1, drinks every bottle that has 2k−1 in its sum. If bottle b is spiked, the sleepers are exactly the numbers in b's sum, so they add up to b.

These are the halving cups. The upper half of a block of width 2j is the numbers whose 2j−1 digit is 1, so the taster who splits blocks of width 2j is the one wearing 2j−1. Route one asks "upper half or lower?" ten times; route two writes the answers down as the digits of the bottle's number.

Route three: read the plan as a table

This one is not in the film. Write the plan as a table, a row for each taster and a column for each bottle, with a mark where the bottle goes into the cup. The column under a bottle is its pattern, so the plan works exactly when all 1000 columns are different. Nothing else matters.

The binary plan is the table whose columns are the bottle numbers written in binary. But any 1000 different columns of ten marks will do. There are 1024×1023×⋯×25 working plans for ten tasters, a number with 2616 digits, and the film's is just the one you can read without a list.

The table also proves the coda. With nine rows there are only 29=512 different columns, and 1000 bottles to give them to, so some two bottles share a column and the king cannot tell them apart. That is the whole of "why not nine". It even says how badly nine fail: at most 511 columns can belong to a single bottle, so at best the king can name the bottle for sure for 511 of the 1000.

A worked case: bottle 643

The film follows bottle 643. In binary it is 1010000011₂, which is 512+128+2+1, so it goes into exactly 4 cups:

Bottle 643, taster by taster
Taster's numberIn 643's sum?After the hourDigit
512yesasleep1
256noawake0
128yesasleep1
64noawake0
32noawake0
16noawake0
8noawake0
4noawake0
2yesasleep1
1yesasleep1

Read the digits from the top and they spell 1010000011₂.

Here are all ten cups at once, as stripes across the cellar. This is the film's halving picture, each row cutting the cellar into twice as many blocks as the row above:

512256128643216842164312505007501000
Gold is in the cup. The grey ends are the 24 spare slots. Bottle 643 is in the cups of 512 + 128 + 2 + 1.

The same bottle, found by halving. Each round, the taster drinks the upper half of whatever is still possible (as well as the upper half of every other block at his level, which is why his cup is fixed in advance):

Halving 1024 slots down to bottle 643
TasterHe drinksThenStill possible
512512–1023asleep512–1023
256768–1023awake512–767
128640–767asleep640–767
64704–767awake640–703
32672–703awake640–671
16656–671awake640–655
8648–655awake640–647
4644–647awake640–643
2642–643asleep642–643
1643asleep643

Halving the 1000 bottles themselves instead, with odd blocks rounded, the largest block left after each round is 500, 250, 125, 63, 32, 16, 8, 4, 2, 1. The film's on-screen count is that largest block, so round five reads 32.

Find the bottle

Spike a bottle, wait the hour and add up the sleepers, or pick one yourself. Take a taster away and watch two bottles start to look the same.

Bottle 643 spiked, ten tasters
TasterDrinks 643?After the hour
512yesasleep
256noawake
128yesasleep
64noawake
32noawake
16noawake
8noawake
4noawake
2yesasleep
1yesasleep

Generalising

Any size of cellar. The fewest tasters for N bottles is the smallest n with 2n≥N, which is ⌈log2N⌉: the counting says no fewer will do, and the binary plan shows that many will. A thousand and twenty-four bottles still need only ten. One more needs eleven.

Maybe nothing was spiked. Then "nobody asleep" has to mean "nothing", and the bottles must leave that pattern alone: 2n≥N+1. The film's plan already does this, because it numbers the bottles from 1 and no bottle from 1 to 1000 has an empty sum. Up to 1023 bottles, ten tasters cover the case for free.

The fewest tasters for one hour
BottlesExactly one spikedMaybe none spiked
212
1044
10077
512910
5131010
1,0001010
1,0231010
1,0241011
1,0251111
2,0001111
1,000,0002020

More than one hour. Suppose there is time for t rounds, and a taster who falls asleep stays asleep. Each taster's story is then one of t+1: asleep after round 1, or 2, …, or t, or never. That gives (t+1)n possible outcomes, and no plan, not even one that changes its mind as tasters drop, can tell apart more bottles than that.

The plan that gets there is binary with a bigger base. Write each bottle's number (less one) in base t+1, one digit per taster. In round r, every taster still awake drinks the bottles whose digit for him is r. A taster who falls asleep after round r has told you his digit is r, and one who never sleeps has told you it is 0.

A thousand bottles, more time
HoursEndings per tasterFewest tastersPatterns they give
12101,024
2372,187
3451,024
4553,125
5641,296
91031,000
101131,331

Two hours bring it down to 7 tasters, because 37=2187. Ten hours, enough to take the film's halving one taster at a time, need only 3.

When the trick fails

Nine tasters. Nine is not "almost enough". The binary plan cut down to nine sends bottle b and bottle b+512 to the same cups, so 976 of the 1000 bottles share their pattern with another one and only 24 are named for sure. Bottle 643 looks exactly like bottle 131. A cleverer nine-taster plan can do better, but by the counting above never for more than 511 of them.

Two spiked bottles. Now the sleepers are everyone who drank either. Under the binary plan bottles 1 and 2 put tasters 1 and 2 to sleep, and so does bottle 3 on its own, and so do 1 and 3, and 2 and 3. The 499,500 pairs of bottles produce only 1013 different sets of sleepers. Counting still gives a floor: 2n must be at least 499,500, so at least 19 tasters are needed, whatever the plan. Getting close to that floor is a real problem, and the subject of group testing.

Checking it

None of the above is left to the proofs. scripts/bottles.mjs reads the film's own numbers and its own tastersFor from components/theme.ts, the file the episode is drawn from, and asserts that for every bottle from 1 to 1000 the page's plan sends the same tasters to sleep, that their numbers add up to the bottle, and that no two bottles share a pattern.

Halving. On 1024 slots, the ten halving cups are checked slot by slot against the ten binary cups, and they are the same. On the film's 1000 bottles, ten rounded halvings are checked to give 1000 different patterns, and none of the ten cups is a binary cup or the complement of one. Bottle 643's trace is run both ways.

Every way of filling the cups. For the tiny cellars where it can be listed, every possible plan is tried, 2,402,234 of them, and the ones that work are counted. The count matches 2n(2n−1)⋯(2n−N+1), and is zero the moment there is one bottle more than there are patterns.

Every way of filling the cups, tried
TastersBottlesWays to fill the cupsWays that work
1242
1380
2425624
251,0240
372,097,15240,320

The rest. The base-(t+1) plan is played out round by round for every one of the 1000 bottles at each number of hours in the table, and one taster fewer is checked to be too few. Every cellar size in the table is checked bottle by bottle, with and without "maybe none". All 499,500 pairs of bottles are tried for the two-bottle count.

The lab. The lab runs the functions in site/lib/bottles-core.mjs, the same text the script imports, and the script checks the pasted copy against the module. In 24,000 random spikings across the lab's cellar sizes and every number of tasters from 1 to 12, the spiked bottle is always among the bottles the sleepers point at, every one of those would have sent the same tasters to sleep, and whenever there are enough tasters the sleepers name exactly one.

Where this shows up

  • Binary numbers. Ten yes-or-no answers pick out one of 210=1024 things. A computer's memory uses the same count: ten address lines are enough to select any one of 1024 locations.
  • Twenty questions. Twenty yes-or-no questions are enough for a million things, since 220 is a little over a million. The bottles show that the questions can even be written down before any answer is heard.
  • Pooled testing. Mixing many samples into one test, so that a few tests cover many people, is the same move as the king's mixtures. Robert Dorfman proposed it in 1943 for screening blood samples, and many laboratories pooled samples for Covid-19 testing in 2020.

Try it yourself

1. How many tasters for 2000 bottles?

11 tasters. Ten give only 210=1024 patterns, and eleven give 2048.

2. Bottle 1000 is the spiked one. Who falls asleep?

The tasters wearing 512 + 256 + 128 + 64 + 32 + 8: 6 of them. Halve 1000 repeatedly and the remainders give the same digits.

3. There is time for two rounds. How few tasters will do?

7 tasters. Each taster ends asleep after round one, asleep after round two, or awake: three stories, and 37=2187 is enough where 36=729 is not. Write each bottle's number, less one, in base 3. In round one each taster drinks the bottles whose digit for him is 1, and in round two the ones whose digit is 2.

4. Bottles 3 and 5 are both spiked. What does the king see, and what can he say?

Tasters 1, 2 and 4 asleep, which adds up to 7. With exactly two spiked he cannot get further: 12 different pairs of bottles put exactly those three to sleep. He does at least know both bottles are among 1 to 7.