-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgold_bar.py
More file actions
35 lines (31 loc) · 804 Bytes
/
Copy pathgold_bar.py
File metadata and controls
35 lines (31 loc) · 804 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
26
27
28
29
30
31
32
33
34
35
# Write a program that given 3 coprime integers,
# returns the least number of cuts needed so that a
# gold bar can be split evenly by any of the integers
import sys
from itertools import combinations
def solve(a,b,c):
prod = a * b * c
nums = b * c, a * c, a * b
find_parts(nums, prod)
def find_parts(nums, prod):
nums = {n: prod//n for n in nums}
atom = min(nums)
parts = [atom]
stack = [atom]
prod -= atom
while stack:
print(parts)
curr = stack.pop(0)
for n in nums:
potential = n - curr
if potential == 33:
print(curr, stack)
print(parts)
input()
if atom > potential > 0 and potential not in parts:
parts.append(potential)
stack.append(potential)
print(sorted(parts))
print("!")
if __name__ == '__main__':
solve(*map(lambda s: int(s), sys.argv[1:]))