Poor Pigs, Unethical experiments, and Poisoned Bacon. | One Line Math Solution
The key to the problem is realizing the number of states possible for a test pig at the end of the testing period. For the case given in the problem, 1 hour tes
The key to the problem is realizing the number of states possible for a test pig at the end of the testing period. For the case given in the problem, 1 hour testing period with 15 minutes cooldown, a pig can test 4 times. Therefore the number of states the pig can be at the end is 5: it either dies on the 1st, 2nd, 3rd, or 4th test, or it lives until the end. (wp pig, wp)\n\nnow imagine a number with an undetermined number of digits, [x x x ...], with each digit only capable of going up to a max of 5. What is the minimum number of digits (or pigs) the number need to encompass 1000 possibilities (or buckets)?\nThe answer is 5 pigs, because 5^5 = 3125.\nTherefore the formula is (t+1)^x=m\nwhere t is number of trials possible, x is minimum number of pigs, m is number of buckets.\n\nVisually the test would look like this:\nThe first pig drinks 4 times, \n[1 x x x x], [2 x x x x], [3 x x x x], [4 x x x x]\nif it dies in the 1st, 2nd, 3rd or 4th testing phase, we know the first digit of the location of the bucket of poison is 1, 2, 3 or 4 respectively. If the pig does not die, we know the first digit is 5.\nThe second pig does something similar, except it varies the second digit,\n[x 1 x x x], [x 2 x x x], [x 3 x x x], [x 4 x x x]\nand similarly we can find out the second digit of the poison bucket location.\nRepeat this for all 5 pigs and we will have the definitive answer to which bucket holds the poison.\n```\nclass Solution {\npublic:\n    int poorPigs(int buckets, int minutesToDie, int minutesToTest) {\n        return ceil(log(buckets)/log((minutesToTest/minutesToDie)+1));\n    }\n};\n```
[]