Day 10
This commit is contained in:
102
day10/input.txt
Normal file
102
day10/input.txt
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
103
|
||||||
|
131
|
||||||
|
121
|
||||||
|
151
|
||||||
|
118
|
||||||
|
12
|
||||||
|
7
|
||||||
|
2
|
||||||
|
90
|
||||||
|
74
|
||||||
|
160
|
||||||
|
58
|
||||||
|
15
|
||||||
|
83
|
||||||
|
153
|
||||||
|
140
|
||||||
|
166
|
||||||
|
1
|
||||||
|
148
|
||||||
|
33
|
||||||
|
165
|
||||||
|
39
|
||||||
|
100
|
||||||
|
135
|
||||||
|
68
|
||||||
|
77
|
||||||
|
25
|
||||||
|
9
|
||||||
|
54
|
||||||
|
94
|
||||||
|
101
|
||||||
|
55
|
||||||
|
141
|
||||||
|
22
|
||||||
|
97
|
||||||
|
35
|
||||||
|
57
|
||||||
|
117
|
||||||
|
102
|
||||||
|
64
|
||||||
|
109
|
||||||
|
114
|
||||||
|
56
|
||||||
|
51
|
||||||
|
125
|
||||||
|
82
|
||||||
|
154
|
||||||
|
142
|
||||||
|
155
|
||||||
|
45
|
||||||
|
75
|
||||||
|
158
|
||||||
|
120
|
||||||
|
5
|
||||||
|
19
|
||||||
|
61
|
||||||
|
34
|
||||||
|
128
|
||||||
|
106
|
||||||
|
88
|
||||||
|
84
|
||||||
|
137
|
||||||
|
96
|
||||||
|
136
|
||||||
|
27
|
||||||
|
6
|
||||||
|
21
|
||||||
|
89
|
||||||
|
69
|
||||||
|
162
|
||||||
|
112
|
||||||
|
127
|
||||||
|
119
|
||||||
|
161
|
||||||
|
38
|
||||||
|
42
|
||||||
|
134
|
||||||
|
20
|
||||||
|
81
|
||||||
|
48
|
||||||
|
73
|
||||||
|
87
|
||||||
|
26
|
||||||
|
95
|
||||||
|
146
|
||||||
|
113
|
||||||
|
76
|
||||||
|
32
|
||||||
|
70
|
||||||
|
8
|
||||||
|
18
|
||||||
|
67
|
||||||
|
124
|
||||||
|
80
|
||||||
|
93
|
||||||
|
29
|
||||||
|
126
|
||||||
|
147
|
||||||
|
28
|
||||||
|
152
|
||||||
|
145
|
||||||
|
159
|
||||||
14
day10/part1.py
Normal file
14
day10/part1.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
lines = sorted(int(x.strip()) for x in open("input.txt"))
|
||||||
|
|
||||||
|
lines.append(lines[-1]+3)
|
||||||
|
lines.insert(0, 0)
|
||||||
|
lines = np.array(lines)
|
||||||
|
|
||||||
|
diff = lines[1:] - lines[:-1]
|
||||||
|
unique, counts = np.unique(diff, return_counts=True)
|
||||||
|
cnt = dict(zip(unique, counts))
|
||||||
|
|
||||||
|
print(cnt)
|
||||||
|
print(cnt[1]*cnt[3])
|
||||||
44
day10/part2.py
Normal file
44
day10/part2.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import numpy as np
|
||||||
|
import operator
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
lines = sorted(int(x.strip()) for x in open("input.txt"))
|
||||||
|
|
||||||
|
lines.append(lines[-1]+3)
|
||||||
|
lines.insert(0, 0)
|
||||||
|
lines = np.array(lines)
|
||||||
|
|
||||||
|
diff = lines[1:] - lines[:-1]
|
||||||
|
|
||||||
|
one_count = 0
|
||||||
|
possibilities = []
|
||||||
|
|
||||||
|
one_cache = {}
|
||||||
|
|
||||||
|
|
||||||
|
def count_one_possibilities(one_cnt: int):
|
||||||
|
if one_cnt not in one_cache:
|
||||||
|
if one_cnt <= 1:
|
||||||
|
one_cache[one_cnt] = 1
|
||||||
|
else:
|
||||||
|
one_cache[one_cnt] = sum(count_one_possibilities(less) for less in range(max(0, one_cnt - 3), one_cnt))
|
||||||
|
return one_cache[one_cnt]
|
||||||
|
|
||||||
|
|
||||||
|
def prod(iterable):
|
||||||
|
return reduce(operator.mul, iterable, 1)
|
||||||
|
|
||||||
|
|
||||||
|
# only 3 and 1 differences are available
|
||||||
|
# 3 has to be taken / calculate possibilities for 1 hops
|
||||||
|
for num in diff:
|
||||||
|
if num == 1:
|
||||||
|
one_count += 1
|
||||||
|
elif num == 3:
|
||||||
|
factor = count_one_possibilities(one_count)
|
||||||
|
if factor > 1:
|
||||||
|
possibilities.append(factor)
|
||||||
|
one_count = 0
|
||||||
|
|
||||||
|
print(prod(possibilities)) # 64793042714624
|
||||||
|
print(one_cache) # {0: 1, 1: 1, 2: 2, 3: 4, 4: 7}
|
||||||
Reference in New Issue
Block a user