-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpig.py
More file actions
25 lines (23 loc) · 780 Bytes
/
pig.py
File metadata and controls
25 lines (23 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution(object):
def poorPigs(self, buckets, minutesToDie, minutesToTest):
"""
:type buckets: int
:type minutesToDie: int
:type minutesToTest: int
:rtype: int
"""
"""
* iterating with T=1 times and 2 Pigs ==> 2^n
* iterating with T=2 times and 2 Pigs ==> 3^n
* therefore, (T+1)^N will give T times to test for N pigs to find the poison
"""
# Number of buckets = n
# Pig death time = m min
# Amount of pigs = x
# Time to find out = t min
# Formula: (1+T)^N
pigs = 0
total_times = (minutesToTest/minutesToDie) + 1
while (total_times)**pigs < buckets:
pigs += 1
return pigs