diff --git a/src/poor_pigs.py b/src/poor_pigs.py new file mode 100644 index 0000000..ed2a231 --- /dev/null +++ b/src/poor_pigs.py @@ -0,0 +1,8 @@ +class Solution: + def poorPigs(self, buckets: int, min_to_die: int, min_to_test: int) -> int: + count = 0 + + while (min_to_test / min_to_die + 1) ** count < buckets: + count += 1 + + return count diff --git a/tests/test_poor_pigs.py b/tests/test_poor_pigs.py new file mode 100644 index 0000000..5c65bcc --- /dev/null +++ b/tests/test_poor_pigs.py @@ -0,0 +1,11 @@ +import pytest + +from src.poor_pigs import Solution + + +@pytest.mark.parametrize( + "buckets,min_to_die,min_to_test,expected", + ((4, 15, 15, 2), (4, 15, 30, 2), (125, 1, 4, 3)), +) +def test_solution(buckets, min_to_die, min_to_test, expected): + assert Solution().poorPigs(buckets, min_to_die, min_to_test) == expected