I just got out from my Math and Logic class with my friend. During the lecture, a well-known math/logic puzzle was presented:

The King has $1000$ wines, $1$ of which is poisoned. He needs to identify the poisoned wine as soon as possible, and with the least resources, so he hires the protagonist, a Mathematician. The king offers you his expendable servants to help you test which wine is poisoned.

The poisoned wine is very potent, so much that one molecule of the wine will cause anyone who drinks it to die. However, it is slow-acting. The nature of the slow-acting poison means that there is only time to test one "drink" per servant. (A drink may be a mixture of any number of wines) (Assume that the King needs to know within an hour, and that any poison in the drink takes an hour to show any symptoms)

What is the minimum amount of servants you would need to identify the poisoned wine?

With enough time and reasoning, one can eventually see that this requires at most ten ($10$) servants (in fact, you could test 24 more wines on top of that 1000 before requiring an eleventh servant). The proof/procedure is left to the reader.

My friend and I, however, was not content with resting upon this answer. My friend added the question:

What would be different if there were $2$ wines that were poisoned out of the 1000? What is the new minimum then?

We eventually generalized the problem to this:

Given $N$ bottles of wine ($N \gt 1$) and, of those, $k$ poisoned wines ($0 \lt k \lt N$), what is the optimum method to identify the all of the poisoned wines, and how many servants are required ($s(N,k)$)?

After some mathsing, my friend and I managed to find some (possibly unhelpful) lower and upper bounds:

$ log_2 {N \choose k} \le s(N,k) \le N-1 $

This is because $log_2 {N \choose k}$ is the minimum number of servants to uniquely identify the $N \choose k$ possible configurations of $k$ poisoned wines in $N$ total wines.

Can anyone help us find an optimum strategy? Besides the trivial one requiring $N-1$ servants. How about a possible approach to start?

Would this problem be any different if you were only required to find a strategy that would for sure find a wine that is not poisoned, instead of identifying all poisoned wines? (other than the slightly trivial solution of $k$ servants)

Justin L.
  • 13,646
  • 22
  • 60
  • 73
  • question is also testing what the boundaries are for allowing logic puzzles that might have limited amounts to do with math itself – Justin L. Jul 24 '10 at 11:09
  • I've removed the `logic` tag, since it might be confused with mathematical-logic. – Tomer Vromen Jul 24 '10 at 12:14
  • 11
    It would be better to change the title of your question to say something about the problem itself. Something like "Math/Logic problem - 1000 cups of wine, one of which is poisoned". This will help people who know the answer look at the question, as well as make it easier to find later. – Edan Maor Jul 24 '10 at 12:24
  • 1
    I have a slight problem with the reasoning here. It all checks out, apart from the fact the poison is slow acting. I can't see a way to manage to test all wines with just 10 servants when it takes the entire time-period for symptoms to show. – workmad3 Jul 24 '10 at 13:38
  • I think it should be "fast-acting". The servant dies immediately after drinking the poisonous wine molecule. – kennytm Jul 24 '10 at 13:41
  • 7
    @workmad3: Number the wines from 0 to 999 and number the servants from 1 to 10. Feed servant k all the wines with a 1 in the kth binary position of their number. Wait an hour. If D is the set of dead servants, the number of the poisoned wine is $\sum_{i \in D} 2^{i-1}$. – Simon Nickerson Jul 24 '10 at 13:51
  • @Justin: Can you please justify the lower bound? My upper bound at N = 1000, k = 7 is smaller that your lower bound (56 < 57.4), and [my simulation](http://www.ideone.com/sRssu) also suggests 56 is an upper bound. – kennytm Jul 24 '10 at 14:48
  • @Simon oh it makes sense now :) And @KennyTM rethinking, if the poison is fast acting, then you only need 1 servant per poisoned wine. – workmad3 Jul 24 '10 at 19:44
  • @workmad3: Hmm you're right. – kennytm Jul 24 '10 at 20:12
  • @KennyTM - the lower bound seemed like a reasonable one at the time, because there are $N \choose k$ unique possible ways that $k$ wines could be distributed, which must be encoded into $s$ bits of servants. The upper bound is very unhelpful and reflects a brute force approach – Justin L. Jul 24 '10 at 20:14
  • 1
    @97832123 could you offer a possible rephrasing that would be more helpful to the community? – Justin L. Jul 24 '10 at 21:50
  • 2
    @Justin: When someone else starts typing in the same question, the duplicate matcher will display your question title for them. Consider what title would make them most likely to click on it. "Can someone help me with a logic problem" will not do a good job of convincing them their exact question has already been asked. – Larry Wang Jul 24 '10 at 23:28
  • 3
    @97832123 @Kaestur - I've edited my title; is it more helpful? =) – Justin L. Jul 24 '10 at 23:31
  • @Justin: Much better, thanks. – Larry Wang Jul 25 '10 at 00:04
  • 1
    A problem that I think might be somewhat related deals with drug testing. If you are testing a rather large population for a drug used by relatively few people and the test is expensive, it can save money to pool the samples--that is, combine samples from groups of, say, 5 or 10 people and test that combined sample for the drug. In this way, a single negative test can eliminate 5 or 10 (or however many in a grouping) people at once. Unfortunately, I don't know of a convenient way to pick the optimal group size and even the optimal group size is just optimizing the expected values. – Isaac Jul 26 '10 at 04:14
  • 1
    (Brute-forcing the optimal group sizes for a first-pass grouping with 24 bottles given various numbers of poisoned bottles and assuming the group size is a divisor of 24: (poisoned bottles,group size) = (1,12), (2,8), (3,6), (4,4), (5,4), (6,3), (7,3), (8,2), (9,2), (10,2), (11,2), (12,1). This is taking "optimal" to mean the greatest expected number of bottles determined safe per servant used.) – Isaac Jul 26 '10 at 05:18
  • Earlier this year I've applied for a programmer position in one company and there I've been given pretty much the same question, but the bottles were 1024 and the servants were 10 and fixed - some easier version of the problem. They were asking what should the servants do to find out the poisoned bottle if the poision needs 24h to react. The answer was every servant drinks of 10 different bottles and one bottle is not opened at all. In other words the answer uses that 2^10 = 1024. – Bor Dec 07 '13 at 20:37
  • Wouldn't you need just 20 servants then? Split them up into two groups, one starting at the lower end of the scale, the other starting at the upper end, and keep going until two sets of servants die? – Canadian Luke Feb 17 '14 at 20:35
  • Seems a strange way of counting the cost: a servant taken away from his other duties for an hour is equal to a servant lost forever? It would make more sense to try and minimize the (expected) number of dead servants. – bof Apr 16 '14 at 03:04
  • Who poisoned my wine? – King Squirrel May 10 '14 at 17:11

11 Answers11


I asked this question on MathOverflow and got a great answer there.

For $k = 2$ I can do it with ${\lceil \log_2 N \rceil + 2 \choose 2} - 1$ servants. In particular for $N = 1000$ I can do it with $65$ servants. The proof is somewhat long, so I don't want to post it until I've thought about the problem more.

I haven't been able to improve on the above result. Here's how it works. Let $n = \lceil \log_2 N \rceil$. Let me go through the algorithm for $k = 1$ so we're all on the same page. Number the wines and assign each of them the binary expansion of their number, which consists of $n$ bits. Find $n$ servants, and have servant $i$ drink all the wines whose $i^{th}$ bit is $1$. Then the set of servants that die tells you the binary expansion of the poisoned wine.

For $k = 2$ we need to find $n$ butlers, $n$ maids, and ${n \choose 2}$ cooks. The cooks will be named $(i, j)$ for some positive integers $1 \le i < j \le n$. Have butler $i$ drink all the wines whose $i^{th}$ bit is $1$, have maid $i$ drink all the wines whose $i^{th}$ bit is $0$, and have cook $(i, j)$ drink all the wines such that the sum of the $i^{th}$ bit through the $j^{th}$ bit, inclusive, mod 2, is $1$. This is how the casework breaks down for butlers and maids.

  • If both butler $i$ and maid $i$ die, then one of the poisoned wines has $i^{th}$ bit $0$ and the other has $i^{th}$ bit $1$.
  • If only butler $i$ dies, then both of the poisoned wines have $i^{th}$ bit $1$.
  • If only maid $i$ dies, then both of the poisoned wines have $i^{th}$ bit $0$.

The second two cases are great. The problem with case 1 is that if it occurs more than once, there's still ambiguity about which wine has which bit. (The worst scenario is if all the butlers and maids die.) To fix the issue with case 1, we use the cooks.

Let $i_1 < ... < i_m$ be the set of bits where case 1 occurs. We'll say that the poisoned wine whose $(i_1)^{th}$ bit is $1$ is wine A, and the other one is wine B. Notice that the sum of the $(i_1)^{th}$ through $(i_2)^{th}$ bits of wine A mod 2 is the same as the sum of the $(i_1)^{th}$ through $(i_2)^{th}$ bits of wine B mod 2, and we can determine what this sum is by looking at whether cook $(i_1, i_2)$ died. The value of this sum determines whether the $(i_2)^{th}$ bit of wine A is 1 or 0 (and the same for wine B). Similarly, looking at whether cook $(i_j, i_{j+1})$ died tells us the remaining bits of wine A, hence of wine B.

One last comment for now. The lower bound is not best possible when $k$ is large compared to $N$; for example, when $k = N-1$ it takes $N-1$ servants. The reason is that any servant who drinks more than one wine automatically dies, hence gives you no information.

Qiaochu Yuan
  • 359,788
  • 42
  • 777
  • 1,145
  • 2
    By the way, I don't know how I feel about this phrase "the astute mathematics student." It seems kind of demeaning. – Qiaochu Yuan Jul 29 '10 at 03:50
  • @Qiaochu - fixed :) i await your solution; a rather large group of my friends are about to give up and go with brute-force using a computer programmer. – Justin L. Jul 29 '10 at 05:15
  • 1
    Some thoughts. If you want to approach the lower bound, you need to be very careful about how many wines each servant drinks. For fixed N and k there is an optimum number of wines which gets you as close to 1 bit of information as possible, but I have no idea how I would decide what sets of wines to drink other than randomly. The probabilistic method might be capable of showing that a strategy which is close to optimal exists with positive probability, but I don't know much about these matters. – Qiaochu Yuan Aug 01 '10 at 05:33
  • Some more thoughts. The above strategy generalizes to a strategy which requires kn + k {n \choose 2} servants, where n = log_k N, but I can't actually prove that it works yet... – Qiaochu Yuan Aug 03 '10 at 00:26
  • This is the best answer I'm probably going to get, and I concluded that this question/puzzle is not one that will be solvable any cleaner than this. Thanks for all your help – Justin L. Sep 07 '10 at 20:25
  • This is similar to binary search? – NebulousReveal Dec 15 '10 at 16:39
  • Never mind... deleted. – hardmath Dec 23 '10 at 19:54
  • You say that you can do it with 65 servants, but the MathOverflow answer seems to say it can be done with 43. So is 65 non-optimal, and is 43 optimal? If I'm reading the answer there correctly, then $1000 \le f(n) \le 2^{(n+1)/2}$ seems to give only a lower bound of $n \ge 19$. – ShreevatsaR Nov 27 '11 at 16:43
  • @ShreevatswaR: $65$ is definitely not optimal. I don't know if $43$ is. – Qiaochu Yuan Nov 27 '11 at 16:50
  • I'm looking for clarification in Qiaochu Yuan's solution. Why isn't n-1 cooks sufficient in place of ${n \choose 2}$ cooks? Test all wines whose 1st & 2nd bit differ. Test all wines whose 2nd & 3rd bit differ. So on. Test all wines whose n-1 & nth bit differ. This will take n-1 cooks. Each one of these tests reduces the number possibilities by half. We may not always be using results of all these n-1 tests. In worst case (where all butlers & maids died), all n-1 results will get used. What am I missing? –  Dec 09 '12 at 20:38
  • @QiaochuYuan: Nice solution +1. Have you considered user52393's suggestion? It seems letting only cooks testing neighbouring bits will suffice since the sum of $i$'th through $j$'th bits can be computed from the sum of all neighbouring bits from $i$'th to $j$'th bits. What do you think? – Hans Mar 31 '18 at 20:42

Solution with 42 servants (also 41):

This gives a solution, for 2 poisons, using 42 servants, for 2187 (=3^7) wines. Represent the wines using trinary number system. You will get 7 Trits. We need to find out the trits of the two poisons.


(A) For Trit A, give wines with values 0,1,2 to 3 unique persons respectively. Do similar tests for rest of the Trits. There will be 7*3=21 such tests.

(B) Mix wines with AB values {00,11,22}. Give it to 1 unique person. Do similar tests on all 2-combination of Trits. There will be C(7,2)=21 such tests.

In Step (A), for a given Trit, at the most, 2 persons will die. If only one person dies, that Trit is resolved. Let's say that some Trits (B,C,E) didn't get resolved.


To link B&C, check if person for BC died in Step(2). If so, BC are {02,11}; else {01,12}.
To link C&E, check if person for CE died in Step(2). If so, CE are {11,22}; else {12,21}.

Total # of tests = 21+21 = 42


The idea is that when comparing Trits (in Step-B), we need to consider only two broad categories. One with only one common value. One with two common values (Not having a common value is impossible). Let's assume that trits A&D did not get resolved.

Follg shows them as having only one common value (0)

    A   D
    0   0
    1   []
    []  2

Follg shows them as having two common values (0,1).

    A   D
    0   0
    1   1
    []  []

Either way, to link them, it is enough to know if at least one of {00,11,22} died. That resolves the values of both the trits.

Note: A solution for 1458 wines, 2 poisons, can be formulated with 41 servants, by using 7 digits (6 Trits + 1 Bit). This trick doesn't add much worth; it might find its use in testing higher number of poisons.
  • 380
  • 3
  • 12
  • 1
    I think your solution with 40 servants might be in error, or I misunderstood your description. Consider the two cases: (i) the bottles labeled 00111 and 22333 are poisoned and (ii) the bottles labeled 00333 and 22111 are poisioned. If I understand your proposed solution correctly, then the same servants die in both cases (in A the servants [AB][02] and [CDE][13], in B the servants [AB][AB] and [CDE][CDE] and in C the servants [AB][CDE]). – Kallus May 07 '14 at 14:35
  • @Kallus Tx for insightful comment! Step-C fails to handle ur case. There is an ambiguity. May be 42 is the optimum. I will post again if I get new ideas. Otherwise, I will delete the the solution for 40. – blackpen May 08 '14 at 23:16
  • @Kallus I removed the solution with 4-base-system. An edge between two 4-base-digits has 16 combinations. If two tests reduce it twice (16/2/2=4), that would still remain ambiguous. The best, I could do was, to solve it with 41 servants (by replacing one Trit with one Bit). Tx for your comments! – blackpen May 10 '14 at 17:19
  • That was so clever! According to Qiaochu Yuan's MathOverflow link, 2187 wines can't be tested with fewer than 42 servants. – Eric Mar 08 '17 at 10:22
  • @blackpen , can you adapt this method of yours to solve this question : https://puzzling.stackexchange.com/questions/12770/find-the-composite-poison-in-the-wine-bottles – Hemant Agarwal Sep 27 '20 at 01:37

Solution with 40 servants:

Represent the wines using base-4 number system. You will get 5 digits (for 4^5=1024 wines)


(A) For digit A, give wines with values 0,1,2,3 to four unique persons respectively. Do similar tests for rest of the digits. There will be 5*4=20 such tests.

(B) Mix wines with AB values {00,11,22,33}. Give it to one unique person. Do similar tests on all 2-combination of digits. There will be C(5,2)=10 such tests (blue graph).

(C) Mix wines with AB values {10,21,32,03}. Give it to one unique person. Do similar tests on all 2-combination of digits. There will be C(5,2)=10 such tests (green graph).

enter image description here

In Step (A), for a given digit, at the most, 2 persons will die. If only one person dies that digit is resolved. If 2 persons die, it means it has two values (one for each poison).

Let's say two digits D&E got two values each. To link them up, you need to look if the person in Step(B) and Step(C) died for D&E. That is enough to link up the digits.


Look at the two graphs.

Assume D has values (1,3). Together, they connect with 0,1,2,3 (all possible values of E). This is the best case. No matter which two values of E you choose, you can uniquely connect them with values of D.

Assume D has values (1,2). Together, they connect with 0,1,2. One value of E (=3) remains unconnected. This is the worst case. Still, no matter which two values of E you select, at least one of them remains connected with values of D. That is enough for us.

  • 380
  • 3
  • 12

I have a solution that uses just 28 slaves. The idea is to use a 28x1000 2-separable testing matrix $M$, where $M_{ij}$ is 1 if slave $i$ drinks bottle $j$ and 0 if he doesn't drink it. A matrix is 2-separable if the boolean OR of any of its two columns is unique. You can read more about such matrices here: https://en.wikipedia.org/wiki/Disjunct_matrix

You can find the actual matrix $M$ here: https://pastebin.com/4yDd1XvG

When I find some free time, I plan to write a short report describing the method I used to find $M$.

UPDATE: A 27x1065 2-separable matrix has been found so it is possible to solve this problem with 27 slaves. See https://oeis.org/A054961

Dmitry Kamenetsky
  • 1,841
  • 7
  • 18
  • Are you still around? Could you please write out the proof of your solution? – Hans Mar 29 '18 at 07:32
  • Hi Hans. The proof is in the matrix that I provided. If you take the boolean OR of any of its two columns then you will find that it is unique. This means that we can use this matrix to identify the location of any two poisoned bottles out of 1000. – Dmitry Kamenetsky Mar 30 '18 at 09:02
  • 1
    Yes, Zhaohui Du actually posted about the 27 solution here as well: https://math.stackexchange.com/a/3330768/346149 – tehtmi Aug 11 '20 at 03:25
  • 1
    How can one modify this matrix method to solve the following question ? https://puzzling.stackexchange.com/questions/12770/find-the-composite-poison-in-the-wine-bottles – Hemant Agarwal Sep 28 '20 at 22:08
  • @HemantAgarwal I believe the problem in your link is EXACTLY the same as the problem here, so the same matrix method would apply to give you 27 slaves. – Dmitry Kamenetsky Sep 30 '20 at 01:08
  • @DmitryKamenetsky , there is a difference. There are 2 days to determine which 2 bottles are the poisoned ones so you can determine what to do on the second day based on your results from the first day. Also, a person has to have had both the poisoned wines to die. Notice that the chosen solution solves the puzzle by using just 18 servants – Hemant Agarwal Sep 30 '20 at 01:23
  • Ah so this is adaptive group testing, while the other one is non-adaptive group testing. The matrix version can only be used for non-adaptive group testing. – Dmitry Kamenetsky Sep 30 '20 at 02:17
  • @DmitryKamenetsky , ok ..but what if there was only one day to find out both the poisoned wines. There are 1000 wines such that 2 of them are poisoned. A person has to drink both the poisoned wines to die. How can we then use this matrix method to solve the question ? – Hemant Agarwal Sep 30 '20 at 03:19
  • well then it become a non-adaptive strategy, because you only have one shot at it. Read about disjunct matrices and group testing: https://en.wikipedia.org/wiki/Disjunct_matrix https://en.wikipedia.org/wiki/Group_testing – Dmitry Kamenetsky Sep 30 '20 at 03:47
  • @DmitryKamenetsky , yes. I realise that it becomes an adaptive strategy . The question though is is how we will need to modify the strategy given above by you to solve this new situation . – Hemant Agarwal Sep 30 '20 at 19:53
  • If there is ONE day then it is a non-adaptive strategy and the matrix method described above will work. If there are TWO days then it is an adaptive strategy and you need to use other methods, which I am not familiar with, so cannot help. – Dmitry Kamenetsky Oct 01 '20 at 00:00
  • @DmitryKamenetsky , according to me, the property that the Boolean OR of any two columns of the matrix is unique, will not give the correct solution for this new problem. In the matrix required to solve this question , the Boolean And of any two columns should be unique . Do you agree with me ? If yes , then would you know what are such matrices called ? – Hemant Agarwal Oct 01 '20 at 21:33
  • @tehtmi , am I right in suggesting in the comment above that the Boolean OR of any 2 columns being unique will not give the correct answer for the following question . It has to be the case that the Boolean And of 2 columns is unique to get the correct answer. This is the question : "There are 1000 wines such that 2 of them are poisoned. A person has to drink both the poisoned wines to die. We have just one day to find both the poisoned wines. How can we then use this matrix method to solve the question?" – Hemant Agarwal Oct 07 '20 at 04:11
  • @HemantAgarwal: I agree. Moreover, if we have a matrix that solves the OR problem, we can take the bitwise complement (NOT) of the entire matrix to get a solution of the AND problem (and vice versa): the OR of the complement of two columns is the complement of the AND of the columns (by De Morgan's law). (And if the set of result columns are distinct, the set of result complements are also distinct.) – tehtmi Oct 07 '20 at 09:46
  • @tehtmi , you mean that you agree with me that the Boolean And of any 2 columns should be unique to solve this new problem ( and not the Boolean OR) ? – Hemant Agarwal Oct 07 '20 at 09:53
  • @HemantAgarwal: Yes. – tehtmi Oct 07 '20 at 10:29

This gives a solution using 60 servants for 1024 wines.Represent the wines using 10-bit binary numbers. Name the bits from A-J. Group the adjacent bits.


What is the value of AB for poisons? Give follg sets of wines to 4 different people.

    AB=00; AB=01; AB=10; AB=11

If only one of them die, AB is completely resolved! If not, we get partial information. Do similar tests on remaining 4 groups.


Consider CD & GH. If we know if set DG=00 died, we can link them. Since we dont know which test would be required, we run all 4-tests:

    CG=00; CH=00; DG=00; DH=00

Similarly for GH and JK. If GJ=00 didnt die, the poisons will be:


Total # of tests/people needed: 5*4 + C(5,2)*4 = 60

PS: If you use groups of 3 (rather than 2), it doesn't improve. If you use groups of 4 or more, it worsens.

  • 380
  • 3
  • 12

There are two solutions Binary and Dimensional.

The binary solution:

We give each bottle a binary number corresponding to its numerical position in the line of bottles. We need enough columns to accommodate the given number of bottles. For instance, if we have 8 bottles :

0 -> 000

1 -> 001

2 -> 010

3 -> 011

4 -> 100

5 -> 101

6 -> 110

7 -> 111

(Note: the first bottle has position 0)

We can test with three columns. Three doses are made one for each column, taking one drop from each bottle if and only if it has a 1 in that column. For instance, the first sample has drops from bottles 4,5,6 and 7.

Each dose is given to one person. We just note which of them die. If none die, the first bottle has poison. If all die, the eight bottle (number 7, binary) is poisoned. If the first and third die, the sixth bottle (binary 5).

The binary solution results in an uncertain number of deaths, averaging 1.5, or 50%. But it uses the smallest number of tasters.

The Dimensional solution:

In the simplest case, treating the bottles as points in a line, we need 1000 servants and 1 dies.

Making a square, we need 32 rows and 32 columns. Some spaces are empty, it won't matter, since empty spaces have the same effect as unpoisoned bottles.

Each dose has drops from 1 row. 64 persons take the dose, two die, indicating a row and a column, the poison bottle is at the intersection.

Making a cube, we have 10 x 10 x 10 bottles. We make 3 doses with a drop from each square, on the x y and z axis. Again, the poisoned bottle is at the intersection.

The progression should now be clear:

Arrangement: Line

Consists of: Points

Test using : Points

Number used: 1000

Number dead: 1

Arrangement: Square

Consists of: Lines

Test using : Lines

Number used: 32 x 2 = 64

Number dead: 2

Arrangement: Cube

Consists of: Squares

Test using : Squares

Number used: 10 x 3 = 30

Number dead: 3

For any given number of bottles, to arrange in n dimensions we take the nth root and round of to the next higher integer. At 5 dimensions, we use 20 testers and 5 die.

Increasing the dimensions can go on and on.

  • 1
  • I assume this solution is only for "1-poison" problem and not for "2-poisons". The "dimensional solution" reaches optimum value when you use log_2(N) dimensions (and thus it becomes the "binary solution"). – blackpen Aug 22 '15 at 00:08
  • Sorry blackpen, I checked the site for a few days and then thought no one was active on this problem! – Chris Sep 02 '16 at 15:26
  • The dimensional solution works for any number of poisoned bottles, and they can be arranged in any order. It will not give a false negative. However, it will give a false positive, if an unpoisoned bottle is surrounded in all dimensions by poisoned bottles. So the King and his guests may keep aside some perfectly good bottles, but they will not ever drink poisoned wine. – Chris Sep 02 '16 at 15:29
  • Chris, Consider 2-dimensional solution with 2-poisons. Each point is a single wine; each line/row stands for a mixture of those wines. You are testing rows/columns. If you found that 4 persons died *(row=1, row=2, col=1, col=2)*, you don't know which diogonal has the two-poisons : *[(1,1),(2,2)]* OR *[(1,2),(2,1)]*. In 2-dimensions, you have 2-diagonals that you need to resolve. In general (dims,diagonals) grow as (1,0),(2,2),(3,4),(4,8), ..($n$,$2^{n-1}$). – blackpen Sep 02 '16 at 21:11

Look at Identifying 2 poisoned wines out of 2^n wines for a easier, guided explanation on how it can be solved using $6n$ tests given $2^n$ wines.

  • 380
  • 3
  • 12

I wrote a code that searches for such an arragement with less than 40 servants. I randomized 1000 groups of 12 servants, representing the servants that drink each bottle. Afterwords, I found two couples of wine bottles that have the same union of servants who drink them. I rerandomized the servants that drink each of the four(or three) bottles in the unions.

That approach found a solution for as much as 36 servants.

  • 1

Two solutions with 20 tests

I am about $10=\lceil\log_21000\rceil$ years late to the party (weird coincidence since it's the solution to $T_*(1,1000)$), yet I am surprised no one has mentioned a solution with $20$ steps for the $T_*(2,1000)$ problem. (The notation I am using is that $T_*(k,N)$ represents the maximum number of steps required to find exactly $k$ poisoned wine bottles in exactly $N$ wine bottles by algorithm $*$ .)

There is an algorithm known as the Generalised Binary Splitting, developed by Hwang, and for the sake of completeness, I shall reproduce that here later.

But first, here's an algorithm for the specific case of $T_s(k=2,N)$ which we claim can be solved in at most $4\lceil\log_4N\rceil$ tests, which gives, for $N=1000$, $T_s(2,1000)=4\lceil\log_41000\rceil=20$ tests.

(Side note : None of these algorithms are proven to be optimal, although both are near optimal, as one can check how much the answers differ from the information lower bound, which is an obvious lower bound, but is in general unachievable).

Here's a proof of the claim.We proceed via induction on $N$. We first see that for $2\le N\le4$, we do need to check every single one of them for identification, thus the number of tests is $N\le 4$, and we also have $T_s(2,N)=4\lceil\log_4N\rceil=4$ and thus the result holds in these cases.

Take any of them as the base case and assume that the statement is true for all number of items $\le N-1$. Then for the case of $N$ items, consider the following algorithm:

  1. If we are in any base case, the number of tests required is at most $4$, so add a $4$ and stop.

  2. If not, make $4$ groups of bottles such that there are $n_1$ groups of $2^{\lceil \log_2(N/4)\rceil}=\lambda$ (say) and another $n_2$ groups of $b\le \lambda$ bottles. This gives us 2 equations: $$n_1\lambda+n_2b=N$$ $$n_1+n_2=4$$ Solving simultaneously gives: $$n_2(b-\lambda)=4\lambda-N$$ This gives us solutions for the pair $(n_2,b)\in \mathbb Z^2$ and we only consider those solutions which satisfy $0\le n_2\le 4$ and $0\le b\le \lambda$. Choose the pair such that $n_2$ is maximum (this minimizes $n_1$, but any solution will work. Just for the sake of a concrete algorithm, we are considering this). Observe that $$\begin{align}\lceil \log_2 b\rceil\le\lceil\log_2\lambda\rceil\end{align}$$ We label the groups with their sizes ($\lambda$ and $b$). Now we test each group, which requires $t_1=4$ tests. Consider the possibilities. If just $1$ group signals poisoned, then we can have a $\lambda$ group signalling or a $b$ group signalling. If $2$ groups signal poisoned, then the possibilities are $2\ \lambda$ groups signalling or $2\ b$ groups signalling or a $\lambda$ and a $b$ group signalling. These scenarios are further referred to as $A,B,C,D$ and $E$ respectively.

    We shall use the result that $1$ poisoned bottle in $n$ bottles can be found in at most $\lceil \log_2 n\rceil$ tests.

    Analysing $C,D$ and $E$ first, we note that identifying the $2$ poisoned bottles in the groups can be done in $$C\to 2\lceil \log_2 \lambda\rceil$$ $$D\to 2\lceil \log_2 b\rceil\le 2\lceil \log_2 \lambda\rceil$$ $$E\to \lceil \log_2 b\rceil+\lceil \log_2 \lambda\rceil\le 2\lceil \log_2 \lambda\rceil$$ steps, and we see that they are all bounded by $2\lceil \log_2 \lambda\rceil$ and thus the total number of steps is bounded by $T_1=2\lceil \log_2 \lambda\rceil+4$ steps. Putting in the definition of $\lambda$ and simplifying, we get the total number of tests to be $$T_1=2\lceil\log_2N\rceil=2\lceil2\log_4N\rceil\le 4\lceil\log_4N\rceil=T_s(2,N)$$ Now we analyse $A$ and $B$. If we are in any base case, go to step $1$. If not, go to the beginning of step $2$ with $N:=\lambda$ for $A$ or $N:=b$ for $B$.

    By induction, this last step would require either $4\lceil\log_4\lambda\rceil$ or $4\lceil\log_4b\rceil$ steps to identify the poisoned bottles. We require the maximum of these 2, which is easy to see once we note that $4\lceil\log_4b\rceil\le 4\lceil\log_4\lambda\rceil$ and hence $T_2=4\lceil\log_4\lambda\rceil+4$. Simplifying again, we have $$T_2=4\left\lceil\frac12\lceil\log_2N\rceil\right\rceil=4\left\lceil\frac12\lceil2\log_4N\rceil\right\rceil\le 4\lceil\log_4N\rceil$$ This completes the proof.$\square$

The Generalised Binary Splitting kind of uses the same idea, but is much more general. The algorithm goes as follows:

  1. If $N\le 2k-2$, test the $N$ items individually. If $N\ge2k-1$, set $l=N-k+1$. Define $\alpha=\lfloor\log(l/k)\rfloor$.
  2. If $N>2d-2$, test a group of size $2^\alpha$. If the outcome is negative, the $2^\alpha$ items in the group are identified as good . Set $N:=N-2^\alpha$ and go to Step 1. If the outcome is positive , use binary splitting to identify one defective and an unspecified number , say $x$, of good items. Set $N:=N-1-x$ and $k=k-1$. Go to Step 1.

This algorithm gives: $$T_G(k,N)=\begin{cases}N\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{for}\ N\le 2k-2\\ (\alpha+2)d+p-1\ \text{for}\ N\ge 2k-1\end{cases}$$ where $p<k$ is a non-negative integer uniquely defined in $l=2^\alpha k+2^\alpha p+\theta,\ 0\le\theta<2^\alpha$.

The proof goes as follows. The case $N\le 2k-2$ is true due to step 1. For $2k-1\le N\le 3k-2$,$\alpha$ must be $0$ and $G$ is reduced to individual testing. Furthermore, $\theta=0$ and $p=l-k=N-2k+1$. Thus $$(\alpha+2)k+p-1=2k+N-2k+1-1=N=T_G(k,N)$$ For $k=1$, $l=N-k+1$. Note that except for $N=2^\alpha$, $G$ is reduced to binary splitting and $$(\alpha+2)k+p-1=\alpha+1=\lfloor\log_2N\rfloor+1=\lceil\log_2N\rceil=T_G(1,N)$$ For $N=2^\alpha$, $G$ spends one more test than binary splitting (by testing the whole set first) and $$(\alpha+2)k+p-1=1+\lceil\log_2N\rceil=T_G(1,N)$$ For the general case $k\ge 2$ and $N\ge 3k-1$, we proceed via induction on $k+N$. From step 2 $$T_G(k,N)=\max\{1+T_G(k,N-2^\alpha),1+\alpha+T_G(k-1,N-1)\}$$ For $N'=N-2^\alpha$ and $k'=k$, $$\begin{align*}l'&=N'-d'+1=N-2^\alpha-k+1=l-2^\alpha\\&=\begin{cases}2^\alpha k+2^\alpha(p-1)+\theta\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{for}\ p\ge 1 \\2^{\alpha-1}k+2^{\alpha-1}(k-2)+\theta\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{for}\ p=0,\ \theta<2^{\alpha-1}\\2^{\alpha-1}k+2^{\alpha-1}(k-1)+(\theta-2^{\alpha-1})\ \text{for}\ p=0,\ \theta\ge 2^{\alpha-1}\end{cases}\end{align*}$$ Hence by induction $$T_G(k,N-2^\alpha)=\begin{cases}(\alpha+2)k+(p-1)-1\ \text{for}\ p\ge 1\\ (\alpha+1)k+(k-2)-1\ \text{for}\ p=0,\ \theta<2^{\alpha-1}\\ (\alpha+1)k+(k-1)-1\ \text{for}\ p=0,\ \theta\ge 2^{\alpha-1}\end{cases}$$ Consequently $$1+T_G(k-N-2^\alpha)=\begin{cases}(\alpha+2)k+p-2\ \text{for}\ p=0,\ \theta<2^{\alpha-1}\\ (\alpha+2)k+p-1\ \text{otherwise}\end{cases}$$ For $k'=k-1$ and $N'=N-1$, $$l'=N'-k'+1=l=\begin{cases}2^\alpha(k-1)+2^\alpha(p+1)+\theta\ \text{for}\ p\le k-3\\ 2^{\alpha+1}(k-1)+\theta\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{for}\ p=k-2\\ 2^{\alpha+1}(k-1)+2^\alpha+\theta\ \ \ \ \ \ \ \ \ \ \text{for}\ p=k-1\end{cases}$$ And hence by induction $$T_G(k-1,N-1)=\begin{cases}(\alpha+2)(k-1)+(p+1)-1\ \text{for}\ p\le k-3\\ (\alpha+3)(k-1)-1\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \text{for}\ k-2\le p\le k-1\end{cases}$$ Which gives $$1+\alpha+T_G(k-1,N-1)=\begin{cases}(\alpha+2)k+p-2\ \text{for}\ p=k-1\\(\alpha+2)k+p-1\ \text{otherwise}\end{cases}$$ Since for $d\ge 2$, $p=0$ and $p=k-1$ are mutually exclusive, $$T_G(k,N)=\max\{1+T_G(k,N-2^\alpha),1+\alpha+T_G(k-1,N-1)\}=(\alpha+2)k+p-1\square$$

Yuzuriha Inori
  • 239
  • 2
  • 7
  • 1
    This sounds like an adaptive testing strategy. I think the question is about non-adaptive testing ("slow-acting poison" and so forth). – tehtmi Jul 19 '20 at 09:23
  • No this is non adaptive. The algorithm is linear. It's basically the known Binary splitting, except the split is done recursively on splits. – Yuzuriha Inori Jul 19 '20 at 09:40
  • 1
    The procedure says test X, if outcome is negative, do this; if outcome is positive do that. How should I understand this to be non-adaptive? – tehtmi Jul 19 '20 at 09:50
  • It's just like the binary splitting. In the original situation with 1 poisoned wine, you split the set into 2 equal parts, and you say the part that tests positive is good. Repeat the procedure with the bad part. Thus the binary splitting also says different things for good and bad tests. This also uses the same exact argument, except the repeating procedure has one more variable to account for the number of poisoned wine bottles. – Yuzuriha Inori Jul 19 '20 at 09:53
  • 1
    I think the procedure you describe for 1 poisoned wine is also adaptive. The standard non-adaptive procedure is to assign to each wine a distinct binary string of length 10 and each servant $i$ gets a mixture of the wines with a $1$ bit in position $i$ (or equivalent). – tehtmi Jul 19 '20 at 10:02
  • That's exactly equivalent to binary splitting ! – Yuzuriha Inori Jul 19 '20 at 10:03
  • It gives an equivalent result, but it is framed non-adaptively. I am able to say exactly what each of the 10 tests is without any dependency on other tests. As you frame it, "repeat the procedure with the bad part," the next test depends on the result. You are not re-testing the "good part". My procedure does (and must because it doesn't know which part is good or bad). It is not always so easy to take an adaptive test and repurpose it as a non-adaptive test. (I am pretty sure it's sometimes impossible.) – tehtmi Jul 19 '20 at 10:09
  • Fair enough. I would believe this is adaptive. And I believe making this algorithm non adaptive would be daunting without putting in an error bound ( the exact case, as you observe, might be impossible ). – Yuzuriha Inori Jul 19 '20 at 10:15
  • I agree with @tehtmi - this algorithm looks adaptive. I don't think 20 tests is possible with non-adaptive algorithms. The best known solution uses 27 tests - see my answer. – Dmitry Kamenetsky Aug 11 '20 at 02:50

You should be able to identify $k$ poisoned bottles in at most $\sum\limits_{i=1}^k (\lceil \textrm{log}_2 N \rceil - \lceil \textrm{log}_2 k \rceil) - 1$ steps, as follows:
Build a binary tree of subsets as for the $k = 1$ case, and follow each path that contains at least one poisoned bottle. After any "round" of tests, you can have at most $k$ subsets containing poison, so the largest number of tests occurs when this limit is reached as early as possible and each poisoned bottle is not identified until round $\lceil \textrm{log}_2 N \rceil$. However, after $n$ rounds there can only be at most $2^n$ subsets, so the $i$'th poisoned bottle can only be isolated after at least $\lceil \textrm{log}_2 i \rceil$ rounds, placing it in $\lceil \textrm{log}_2 N \rceil - \lceil \textrm{log}_2 i \rceil$ subsets.
I subtract $1$ because I already know the root (the set of all bottles) contains poison and thus I don't need to check it.

  • This sounds like an adaptive testing strategy. I think the question is about non-adaptive testing ("slow-acting poison" and so forth). (This means, you wouldn't be able to choose what to test next based on the results of a previous test. All the servants must be given their wine cocktail at the same time.) – tehtmi Jul 19 '20 at 09:54
  • Ah, I must have been thrown off by some of the other adaptive answers. – AxiomaticSystem Jul 20 '20 at 01:06

Technically, a molecule of wine can't contain a molecule of poison, but I'm splitting hairs. I know what you mean.

I consider this problem impossible to solve because of the time constraints. Any time taken to find the correct bottle is taken away from the time necessary for the poison to kill the servant.

If one's objective were to protect the king, it could be done with a single servant. Simply give wine to the servant an hour before the king is ready for his. If the servant dies, pick another bottle. It could take up to 999 tries to find the right bottle, but the king would be safe, and only one servant's life is put at risk.

I don't know about you, but it would probably take me the whole hour to number a thousand bottles. Mixing wines would seem equally time consuming.

  • 25
  • 1