aboutsummaryrefslogtreecommitdiffstats
path: root/458
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-08-06 04:57:11 +0000
committerterminaldweller <thabogre@gmail.com>2022-08-06 04:57:11 +0000
commitaf58b80576bfc68fe75c3fd8ca4b846264581224 (patch)
tree24eaf5faf809632bd5e725a6e6417f3d6eb0be27 /458
parentupdate (diff)
downloadleetcode-af58b80576bfc68fe75c3fd8ca4b846264581224.tar.gz
leetcode-af58b80576bfc68fe75c3fd8ca4b846264581224.zip
update
Diffstat (limited to '458')
-rwxr-xr-x458/main.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/458/main.py b/458/main.py
new file mode 100755
index 0000000..62e2482
--- /dev/null
+++ b/458/main.py
@@ -0,0 +1,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()