Ok, this is my solution. This may end up similar to the algorithm 124816 proposed, but I am not sure I understood his solution. So I will give you mine. I arrived at my solution independently from 124816 although it does seem similar.

You label each barrel of wine with a 5 digit binary label. "But wait," you say "5 digits in binary can only enumerate 32 barrels from 00000 (0) to 11111 (31)." You are right, but I did not say the labels were unique.

There is only one barrel labeled 11111. For every barrel that has a label that has exactly one zero, there are two barrels carrying that label. This there are two barrels with the label 01111 and two more barrels labeled 10111, etc. For every label with exactly two zeros, there are four barrels having that same label.

In general, if a label has n zeros (0<=n<=5) there are 2^n barrels having that same label. Now lets see how many barrels we can label using this scheme.

There will be 2^5=32 barrels having the number 000000.

For numbers with 4 zeros there are 5 possible labels and 16 barrels per label. 5x16=80.

For barrels with 3 zeros, there are 5 choose 3 = 10 possible labels, and 2^3=8 barrels per label. 8x10 = 80 total barrels that can be labeled.

For barrels with 2 zeros, there 5 choose 2 = 10 possible labels again with 4 barrels per label. 10x4= 40 barrels.

And for barrels with one zero there are 5 possible labels with 2 barrels per label, which equals 10 barrels.

As mentioned before there is only one barrel that is labeled 11111.

So the grand total is 32+80+80+40+10+1=243 barrels. Thus we can label 243 barrels using the above described scheme. We label 240 barrels and throw away three labels.

Now we get to the slaves. We number the slaves from 1 to 5. Each slave number will be a significant position in a binary barrel label number. We take the slaves to each barrel, and look at the label for the barrel. The slaves whose numbers correspond to significant positions which have "1" on the barrels label drink. The slaves who correspond to significant positions which have "0" on the label don't drink. Thus, a label "10011" means that slaves number 1, 2 and 5 drink. A label "00100" means that only slave number 3 drinks.

After 24 hours we have 0-5 dead slaves. At this point we get a little sad and wonder why couldn't the problem have been worded in terms of rats, or something similar. But we keep on going; by the numbers of the dead slaves, we can determine which label is associated with the poisonous wine. The label with the poisonous wine is the one that has 1's in the positions associated with dead slaves. Thus if the first and second slave died, the poisonous label was 00011.

If all slaves died, it kind of sucks for them, but we are in luck - that means the poisonous label was 11111 and there is only one barrel with this label, so we know which was the poisonous barrel.

But if some slaves survived we will know the poisonous label but will have multiple barrels carrying this label.

The number of slaves surviving will be equal to the number of zeros in the poisonous label. That is because the number of dead slaves is equal to the number of ones in the poisonous label. As discussed above, the number of barrels carrying any label is equal to 2^n where n is the number of zeros in the label.

Thus, after 24 hours we are left with n slaves still living and 2^n barrels that are still suspicious (i.e., one of them is poisonous). If you have followed me thus far, solving this part will be trivial. We tear down the old labels and relabel the 2^n barrels with new n digit binary numbers. This time there is only one barrel per label. We also number the slaves from 1 to n to signify a significant position. We have each slave drink from each barrel that has a "1" in his significant position. And then we wait to see who dies. The poisonous barrel is the one whose label has "1" in every significant position associated with a dead slave.

Well, this is it, I hope you enjoyed it, and yes I am brilliant.