Poor Pigs
Intuition
Solution
class Solution(object):
def poorPigs(self, buckets, minutesToDie, minutesToTest):
"""
:type buckets: int
:type minutesToDie: int
:type minutesToTest: int
:rtype: int
"""
n = minutesToTest // minutesToDie
pigs = 0
max_buckets = 1
while max_buckets < buckets:
max_buckets *= n + 1
pigs += 1
return pigs
# TestCode
import unittest
class TestSolution(unittest.TestCase):
def test_case1(self):
self.assertEqual(
Solution().poorPigs(
4, 15, 15
),
2
)
def test_case1(self):
self.assertEqual(
Solution().poorPigs(
1000, 15, 60
),
5
)
if __name__ == '__main__':
unittest.main()