VERY EASY arithmetics: the right way to ENCODE the buckets (LESS than 10 lines, beats 100%)
Change the question into:\n\nThere are 100 buckets where ONE of them is poisonous. The pig that drinks the poisonous liquid will die in 1 minute. How can we fin
Change the question into:\n\nThere are **100 buckets** where **ONE** of them is poisonous. The pig that drinks the poisonous liquid will die in **1 minute**. How can we find out which one is poisonous in **1 minute**(ONE PASS) with **7 pigs**.\n\nThe number **7** here is not chosen randomly. **7** is the minimal number of **binary** digits that can encode number 0-99. We mark the bucket as 0-99 in binary codes, which is 0000000 ... 1100100. We let the first pig drink all buckets whose first digit is 1, then the second, till all seven pigs drinks all buckets.\n\nAfter one minute, if the first pig dies, the first digit of poisonous bucket is one, otherwise zero. This trend is the same for all pigs.\n\nIf we are allowed to find the result not in ONE pass but in **k passes**, we can change our base for encoding to **k+1**. Like the sample question, where there are **1000 buckets**, **4 passes** (pig dies in 15 minutes and 60 minutes are allowed), we can encode number 0-999 in **5 digits** of **5 base numbers**.\n\n0->00000\n1->00001\n2->00002\n3->00003\n4->00004\n5->00005\n...\n1000->13000\n\nIn the first pass, the first pig drinks from buckets whose first digit is **1**, **second** pig drinks from buckets whose **second** digit is **1**.\nShould a pig dies, the digit that pig "represents" would be **1**. Like, if the second and third pigs die, we can pin down the second and third digits **1** and after the first pass, the "poisonous code" is cracked from ????? to **?11??**.\nIf this is the case, then we have only three pigs in the second round. But don\'t worry, since the second and third digit of the poisonous code is now one for sure, we let the first pig drink from buckets whose first digit is **2**, then we skip the second and the third digits, we let the fourth pig and the fifth pig to drink buckets whose fourth and fifth digit is **2** respectively.\nShould a lucky pig survives all rounds, the digit that pig represents is **0**.\n\nHere the code:\nA logrithm would make it even easier.\n\n```\nint poorPigs(int buckets, int minutesToDie, int minutesToTest)\n{\n    if(buckets==1)\n        return 0;\n    int digits = 1;\n    int base = minutesToTest / minutesToDie + 1;\n    int timer = base;\n    while(buckets>timer)\n    {\n        timer*=base;\n        digits+=1;\n    }\n    return digits;\n}\n```\n\n\n\n
[]