day 10 challenge

This commit is contained in:
Thibaud Gasser 2020-12-10 22:35:47 +01:00
parent f20fc27a1c
commit f74713233a
2 changed files with 123 additions and 0 deletions

24
day10/day10.py Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
from collections import Counter
def part1(adapters):
counts = Counter()
# 1 for the socket, of 3 for the device
for current, next in zip([0] + adapters, adapters + [3]):
counts[next - current] += 1
return counts[1] * counts[3]
def part2(adapters):
counts = Counter({0: 1})
for jolt in adapters:
s = counts[jolt - 1] + counts[jolt - 2] + counts[jolt - 3]
counts[jolt] = s
return max(counts.values())
if __name__ == "__main__":
adapters = sorted(int(l.rstrip()) for l in open("input.txt"))
print(part1(adapters))
print(part2(adapters))

99
day10/input.txt Normal file
View File

@ -0,0 +1,99 @@
151
94
14
118
25
143
33
23
80
95
87
44
150
39
148
51
138
121
70
69
90
155
144
40
77
8
97
45
152
58
65
63
128
101
31
112
140
86
30
55
104
135
115
16
26
60
96
85
84
48
4
131
54
52
139
76
91
46
15
17
37
156
134
98
83
111
72
34
7
108
149
116
32
110
47
157
75
13
10
145
1
127
41
53
2
3
117
71
109
105
64
27
38
59
24
20
124
9
66