Solve 2020/10

master
Alfred Melch 4 years ago
parent 514b90c84e
commit faff40a314

@ -0,0 +1,99 @@
77
58
25
92
14
154
105
112
147
63
84
109
24
129
49
102
130
128
134
88
95
70
80
4
153
17
145
122
39
117
93
65
3
2
139
101
148
37
27
1
87
64
23
59
42
146
43
151
116
46
115
118
131
94
19
33
12
107
10
7
73
78
53
11
135
79
60
32
141
31
140
98
136
72
38
152
30
74
106
50
13
26
155
67
20
66
91
56
34
125
52
51
18
108
57
81
119
71
144

@ -0,0 +1,21 @@
with open('input', 'r') as f:
adapters = list(map(int, f.readlines()))
adapters.sort()
print(adapters)
num1 = 0
num3 = 1
prev = 0
for adapter in adapters:
if adapter - prev == 1:
num1 += 1
if adapter - prev == 3:
num3 += 1
prev = adapter
print(f'Number of adapters: {len(adapters)}')
print(f'1-jolt: {num1}, 3-jolt: {num3}')
print('Solution:')
print(num1 * num3)

@ -0,0 +1,18 @@
from collections import defaultdict
with open('input', 'r') as f:
adapters = list(map(int, f.readlines()))
adapters.append(0)
adapters.sort()
adapters.append(adapters[-1] + 3)
print(adapters)
countMap = defaultdict(int)
countMap[0] = 1
for adapter in adapters:
for target in range(1, 4):
countMap[adapter + target] += countMap[adapter]
print(countMap[adapters[-1]])
Loading…
Cancel
Save