Source

I got this problem from Rustan Leino, who got it from Vladislav Shcherbina.

I solved it and wrote up my solution.

Problem

You have 240 barrels of wine, one of which has been poisoned. After drinking the poisoned wine, one dies within 24 hours. You have 5 pigs whom you're willing to sacrifice to determine which barrel contains the poisoned wine. How do you achieve this in 48 hours?

Solution
Reveal

Because there are no more than $3^5$ barrels, it's possible to label each barrel with a different integer $i$ such that $0 \leq i < 3^5.$ So, label them that way, writing out each integer as a five-digit base-three number, padding to the left with zeroes as necessary.

Next, label the pigs 1, 2, 3, 4, and 5. For each pig $i,$ feed it some wine from each barrel whose $i$th digit is a 1. Then, 24 hours later, for each surviving pig $i,$ feed it some wine from each barrel whose $i$th digit is a 2.

The poisoned wine is in the barrel whose label has 1s in the positions corresponding to pigs who die on the first day, 2s in the positions corresponding to pigs who die on the second day, and 0s in the positions corresponding to pigs who don't die on either day. This uniquely identifies the poisoned barrel since the barrels all have different labels.

The reason this works is straightforward. Let $n$ be the poisoned barrel's label. For any pig whose position in $n$ is a 1, it will drink from the poisoned barrel at the beginning and die on the first day. For any pig whose position in $n$ is a 2, it won't drink from the poisoned barrel at the beginning but it will drink from that barrel 24 hours later; thus, it will die on the second day. For any pig whose position in $n$ is a 0, it will never drink from the poisoned barrel, so it won't die.

The following optimization will save some wine. After the first 24 hours, there will be many barrels that are obviously not poisoned. Those are the barrels with a 1 in a position corresponding to a still-alive pig and/or a non-1 in a position corresponding to a dead pig. They can thus be removed from consideration and not fed to any pigs in the second round of feeding.