aboutsummaryrefslogtreecommitdiffstats
path: root/458/main.py
blob: 62e24828955856f9c2353f545e4e0485f9650b67 (plain) (blame)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# used the hints

import math


class Solution:
    def poorPigs_v2(
        self, buckets: int, minutesToDie: int, minutesToTest: int
    ) -> int:
        number_of_tries: int = math.floor(minutesToTest / minutesToDie)
        if number_of_tries == 1:
            boundary = math.log(buckets, 10) / math.log(2, 10)
            return math.ceil(boundary)
        else:
            boundary = math.log(buckets, 10) / math.log(number_of_tries, 10)
            return math.ceil(boundary)

    def poorPigs(
        self, buckets: int, minutesToDie: int, minutesToTest: int
    ) -> int:
        result: int = 0
        number_of_tries: int = math.floor(minutesToTest / minutesToDie)
        while pow(number_of_tries + 1, result) < buckets:
            result += 1
        return result


def main():
    solution = Solution()
    print(solution.poorPigs(1000, 15, 60))
    print(solution.poorPigs(4, 15, 15))
    print(solution.poorPigs(4, 15, 30))
    print(solution.poorPigs(8, 15, 40))


if __name__ == "__main__":
    main()