Skip to content

Commit

Permalink
"Poor Pigs" solution
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelote committed Oct 29, 2023
1 parent 99d7e28 commit a3da9c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/poor_pigs.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/test_poor_pigs.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a3da9c1

Please sign in to comment.