From a3da9c111fbf15a252ec128812ae438b16a6274e Mon Sep 17 00:00:00 2001 From: Pavel Karateev Date: Sun, 29 Oct 2023 18:52:08 +0100 Subject: [PATCH] "Poor Pigs" solution --- src/poor_pigs.py | 8 ++++++++ tests/test_poor_pigs.py | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/poor_pigs.py create mode 100644 tests/test_poor_pigs.py 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