Two diagrams to help understanding
Especially with the last hint in the question the solution is pretty straigtforward. In fact, when the number of rounds = 1, the each pig correspond to 1 bit of
Especially with the last hint in the question the solution is pretty straigtforward. In fact, when the number of rounds = 1, the each pig correspond to 1 bit of information. We can show how the solution is constructed. Consider the diagram below. Here we have 8 buckets, and the number of rounds = 1 (for example when both `x=15` and `y=15`). The first pig drinks the first four buckets, the second pig drinks buckets of size 2, interleaving two buckets, and the last pig drinks buckets of size 1, interleaving 1 bucket. If a pig dies it is encoded as `1`, otherwise `0`. We can see that 3 pigs encode all 8 cases here. Encoded string are shown at the bottom. Hence for `b=8, x=15, y=15` the answer is `3`.\n\n![image](https://assets.leetcode.com/users/images/546342db-390a-4e5e-adf9-d124abec0b74_1605349509.07897.png)\n\nAs the number of rounds increase, each pig can represent more information; but this is rather difficult to grasp at the beginning. We now consider the following diagram. Here we have 9 buckets and the number of rounds = 2 (for example when both `x=30` and `y=15`). You see how the pigs drink from buckets at round 1 and 2. If a pig dies in round 1, no problem! You set its value to `2`! If it dies in round 2, set it to `1`. Otherwise set it to `0`. You can see that 2 pigs encode all 9 cases here. Encoded string are shown at the bottom. Hence for `b=9, x=30, y=15` the answer is `2`.\n\n![image](https://assets.leetcode.com/users/images/bafa63d4-1dae-4ef5-8b81-67eb85fafd86_1605349693.3704822.png)\n\n```\nclass Solution:\n    def poorPigs(self, b, y, x):\n        T = x//y\n        x = 0\n        while (T+1)**x < b:\n            x += 1\n        return x\n```
[]