Identifying 2 poisoned wines out of 2^n wines
This problem has been asked and discussed in following posts:
- Logic problem: Identifying poisoned wines out of a sample, minimizing test subjects with constraints,
- Finding 2 poisoned bottles of wine out of a 1000
- Identifying poisoned wines
There are better optimized solutions to this problem. But, for easy comprehension, I formulated following solution with 6n tests (for $2^n$ wines). Are there any loop holes in it?
Part-I
Let's say there are $2^5$ (=32) wines. Represent them using binary system using 5 bits:
A-B-C-D-E
Give wines with A=$0$ to one person. Give wines with A=$1$ to another person. Do such tests for all bits (10 tests). Let's say you got a result like the following:
(0|1)-(0)-(1)-(0|1)-(0|1)
Bits B&C have fixed values (B=$0$. C=$1$). Bits A,D,E have two probable values each. The solution must be one from the following enumerations (Two solutions if you count both (a,b) and (b,a)). We represent the solutions in binary/decimal forms for clarity. It is easy to prove that they are just pairs of numbers with a constant sum (=27 in our case).
(00100, 10111) = (4,23) (00101, 10110) = (5,22) (00110, 10101) = (6,21) (00111, 10100) = (7,20) (10100, 00111) = (20,7) (10101, 00110) = (21,6) (10110, 00101) = (22,5) (10111, 00100) = (23,4)
Part-II
Renumber the wines from (0,1,2,3,4,5 ...) to (0,1,4,9,16,25 ...) and put them into a bigger set of size $(2^5)^2$=$2^{10}$=1024 (We are squaring the numbers). Only 32 of the 1024 will be actual wines. Fill the rest of them with water.
Repeat the tests similar to that ones from Part-I on this bigger set (2*10=20 tests). This will give another set of solutions. Ignore all the solutions which contain water in one or both the bottles. Only the pair that matches with the corresponding pair from Part-I will be the actual solution (Two solutions if you consider duplicates).
If you get these from Part-I: $$(a,b),(c,d),(e,f),(f,e),(d,c),(b,a)$$ and if you get these from Part-II: $$(a^2,b^2),(g^2,h^2),(c^2,i^2),(i^2,c^2),(h^2,g^2),(b^2,a^2)$$
then the solution must be (a,b).
The reason is: Part-I satisfies $x+y=c1$, and Part-II satisfies $x^2+y^2=c2$. Given that x>=0 & y>=0, there is only one solution that satisfies these conditions (two solutions if you consider duplicates).
Number of tests required for $2^5$ wines with 2 poisons = $2*5 + 2*(2*5)$ = 30.
Number of tests required for $2^n$ wines with 2 poisons = $2*n$ + $2*(2*n)$ = $6n$.
Solution 1:
If $$a+b=c+d$$ and $$a^2+b^2=c^2+d^2$$ then $a=c$ and $b=d$ is not always true. Let $$a=1\quad b=2 \quad c=2 \quad d=1$$ and note that $a\neq c$ and $b\neq d$.
So your test may work, but not for the reason you specified. For example, let there be $4$ wines labelled $0,1,2,3$ and let the wines $0,3$ be poisoned. In binary this is $(00,11)$. Your first test yields the solutions $$00,11\quad 01,10$$ Squaring, we have the wines labelled $0,1,4,9$ with the wines $0,9$ poisoned. In binary this is $(0000,1001)$. Your second test yields the solutions $$0000,1001\quad 0001,1000$$ which is $0,9$ and $1,8$. The last pairs are not perfect squares, yielding the solution $0,9$.
Squaring uniquely identifies which solution is correct because only two pairs of integers can satisfy $x+y=k_1$ and $x^2+y^2=k_2$, as these are the equations of a line and circle and can only intersect at two points. The two pairs are always mirrored solutions $(a,b)$ and $(b,a)$. These are the same two poisoned wines, so the test works.
Solution 2:
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
I plan to write a short report describing the method I used to find $M$.