-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbomb_baby.py
51 lines (37 loc) · 1.46 KB
/
bomb_baby.py
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
39
40
41
42
43
44
45
46
47
48
49
50
class UnitTest:
def __init__(self, m, f, expected_result):
self.m = m
self.f = f
self.expected_result = expected_result
def answer(m, f):
"""
:param m: [int] number of Mach bombs needed
:param f: [int] number of Facula bombs needed
:return: minimum number of iterations to produce a strong enough combo
"""
generations = 0
current_iteration = [int(m), int(f)]
while min(current_iteration) > 1 and max(current_iteration) > 1:
if max(current_iteration) % min(current_iteration) == 0:
return "impossible"
generations += max(current_iteration) / min(current_iteration)
current_iteration.sort()
current_iteration[-1] = max(current_iteration) % min(current_iteration)
return generations + max(current_iteration) - 1
if __name__ == "__main__":
unit_tests = [UnitTest(2, 1, 1),
UnitTest(4, 7, 4),
UnitTest(2, 4, "impossible")
]
count = 0
for test in unit_tests:
count += 1
result = answer(test.m, test.f)
if result != test.expected_result:
print "[!] Test {} failed.".format(count)
print "\tm: {}".format(test.m)
print "\tf: {}".format(test.f)
print "\texpected result: {}".format(test.expected_result)
print "\tactual result: {}".format(result)
else:
print "[+] Test {} passed.".format(count)