-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.py
32 lines (27 loc) · 838 Bytes
/
10.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
from functools import lru_cache
lines = [0]
with open("input10.txt") as f:
lines.extend([int(x) for x in f.readlines()])
lines.sort()
lines.append(lines[len(lines)-1] + 3)
diffs = []
for i in range(1, len(lines)):
diffs.append(lines[i]-lines[i-1])
print(lines)
print(diffs)
diffs_1 = diffs.count(1)
diffs_3 = diffs.count(3)
print("Diffs 1: {}".format(diffs_1))
print("Diffs 3: {}".format(diffs_3))
print("Product: {}".format(diffs_1 * diffs_3))
@lru_cache()
def calc_adapter_recurse(current, target, adapters):
if current == target:
return 1
options = [i for i in adapters if 1 <= i - current <= 3 ]
count = 0
for option in options:
count += calc_adapter_recurse(option, target, adapters)
return count
count = calc_adapter_recurse(0, lines[len(lines)-1], tuple(lines))
print(count)