Be sure to try the blue-haired puzzle first.
The answer is that you can test all the cases of wine, positively identifying the one that will turn your hair blue.
(a little spoiler space)
In fact, you can test up to 243 cases this way.
This puzzle can be solved by working backward from how many cases of wine you’ll be able to test on the second day, based on how many dukes’ hair turns blue the first night. For example, if no dukes’ hair turned blue during the first night, on the second night you’ll be able to test 32 cases of wine conclusively, because you still have 5 dukes and 2^5 = 32. I.E. an arrangement like this, with dukes A,B,C,D, and E:
Case A B C D E
1 drinks drinks drinks drinks drinks
2 drinks drinks drinks drinks
3 drinks drinks drinks drinks
4 drinks drinks drinks
5 drinks drinks drinks drinks
6 drinks drinks drinks
7 drinks drinks drinks
8 drinks drinks
9 drinks drinks drinks drinks
10 drinks drinks drinks
11 drinks drinks drinks
12 drinks drinks
13 drinks drinks drinks
14 drinks drinks
15 drinks drinks
17 drinks drinks drinks drinks
18 drinks drinks drinks
19 drinks drinks drinks
20 drinks drinks
21 drinks drinks drinks
22 drinks drinks
23 drinks drinks
25 drinks drinks drinks
26 drinks drinks
27 drinks drinks
29 drinks drinks
So working backwards, on the first day, there can be 32 cases of wine that no duke drinks, because then if no one turns blue, you have the above situation and you can nail down exactly which case is tainted on the second day.
If one duke turns blue on the first day, you can distinguish 16 wines on the second day: 2^4 is 16, and you have cases 1-16 above without E. So on day one, each duke should drink 16 wines that no other duke drinks — 5 dukes * 16 cases = 80 cases tested by exactly one duke each on day one.
Likewise, if two dukes turn blue on day one, you can distinguish 8 wines on day two: 2^3 = 8, and you have cases 1-8 above with just dukes A, B, and C.
There are 10 ways to pick two dukes out of 5: 10C2 = 5 * 4 / 2. So you have 10 combinations, drinking 8 wines each that no other pair of dukes drink, or 80 cases tested by exactly two dukes each on day one.
If three dukes turn blue on day one, you can distinguish 4 wines on day two: 2^2 = 4, and you have cases 1-4 above with just dukes A, and B.
There are 10 ways to pick three dukes out of 5: 10C3 = 5 * 4 / 2. So you have 10 combinations, drinking 4 wines each, or 40 cases tested by exactly three dukes each on day one.
If four dukes turn blue on day one, you can distinguish 2 wines on day two: 2^1 = 2, and you have cases 1-2 above with just duke A.
There are 5 ways to pick four dukes out of 5. So you have 5 combinations, drinking 2 wines each, or 10 cases tested by exactly four dukes each on day one.
Finally, you can have all five dukes share one wine on day one. If they all turn blue, that’s the case.
So on day one you have:
- 32 cases that no duke tests
- 80 cases where each case is tested by exactly one duke
- 80 cases where each case is tested by exactly two dukes
- 40 cases where each case is tested by exactly three dukes
- 10 cases where each case is tested by exactly four dukes
- 1 case that that is tested by all five dukes