-
Notifications
You must be signed in to change notification settings - Fork 0
/
10-1.py
46 lines (34 loc) · 893 Bytes
/
10-1.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
adapters = []
with open("10.in", "r") as file:
for l in file:
l = int(l.strip())
adapters.append(l)
dev_adapter = max(adapters)+3
adapters.append(dev_adapter)
#Algorithm is probably a search tree?
#Using recursion, if it exceeds joltage and doesn't use all adapters,
#kick back up from the lowest level of recursion
adapters.sort()
print(adapters)
curr = 0
diff = {}
diff[1] = 0
diff[2] = 0
diff[3] = 0
for i in adapters:
diff[i-curr] += 1
curr = i
print(diff[1]*diff[3])
def next_adapter(l, curr, diffs):
if len(l) == 0:
return True, []
for i in l:
if 0 < i - curr <= 3:
new_l = l.copy()
new_l.remove(i)
diffs.append(i-curr)
end, diffs = next_adapter(new_l, i, diffs)
if end:
return True, diffs
return False, diffs
#print(next_adapter(adapters, 0))