Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit af952d7

Browse files
committed
added 2016/day10
1 parent a3693e5 commit af952d7

File tree

4 files changed

+334
-1
lines changed

4 files changed

+334
-1
lines changed

‎2016/day10/answers.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
93
2+
47101

‎2016/day10/input.txt‎

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
bot 135 gives low to bot 27 and high to bot 166
2+
bot 57 gives low to bot 4 and high to bot 186
3+
bot 115 gives low to output 2 and high to bot 80
4+
bot 44 gives low to bot 175 and high to bot 88
5+
bot 167 gives low to bot 42 and high to bot 168
6+
bot 18 gives low to bot 32 and high to bot 89
7+
bot 199 gives low to bot 75 and high to bot 40
8+
bot 129 gives low to bot 178 and high to bot 147
9+
bot 163 gives low to bot 49 and high to bot 160
10+
value 2 goes to bot 143
11+
bot 176 gives low to bot 139 and high to bot 117
12+
bot 194 gives low to bot 11 and high to bot 37
13+
bot 99 gives low to bot 163 and high to bot 138
14+
value 53 goes to bot 9
15+
bot 159 gives low to output 1 and high to bot 207
16+
bot 0 gives low to bot 105 and high to bot 13
17+
bot 6 gives low to bot 66 and high to bot 116
18+
bot 81 gives low to bot 54 and high to bot 10
19+
bot 27 gives low to bot 188 and high to bot 199
20+
bot 186 gives low to bot 84 and high to bot 123
21+
bot 154 gives low to bot 21 and high to bot 107
22+
bot 188 gives low to bot 92 and high to bot 75
23+
bot 164 gives low to bot 115 and high to bot 28
24+
bot 106 gives low to bot 48 and high to bot 155
25+
bot 193 gives low to bot 101 and high to bot 110
26+
bot 136 gives low to bot 166 and high to bot 152
27+
bot 7 gives low to bot 156 and high to bot 24
28+
bot 103 gives low to bot 182 and high to bot 0
29+
bot 101 gives low to bot 16 and high to bot 72
30+
bot 86 gives low to bot 102 and high to bot 48
31+
bot 78 gives low to bot 177 and high to bot 113
32+
value 17 goes to bot 198
33+
bot 54 gives low to bot 161 and high to bot 111
34+
bot 46 gives low to bot 74 and high to bot 39
35+
bot 22 gives low to bot 56 and high to bot 161
36+
bot 5 gives low to bot 186 and high to bot 123
37+
bot 137 gives low to bot 202 and high to bot 85
38+
bot 202 gives low to bot 108 and high to bot 118
39+
bot 174 gives low to bot 0 and high to bot 21
40+
bot 119 gives low to bot 68 and high to bot 53
41+
bot 151 gives low to bot 83 and high to bot 164
42+
bot 160 gives low to bot 33 and high to bot 97
43+
bot 76 gives low to bot 40 and high to bot 120
44+
bot 60 gives low to bot 103 and high to bot 174
45+
bot 203 gives low to bot 120 and high to bot 132
46+
bot 157 gives low to bot 116 and high to bot 11
47+
bot 98 gives low to bot 208 and high to bot 16
48+
bot 142 gives low to bot 114 and high to bot 71
49+
bot 143 gives low to bot 198 and high to bot 146
50+
bot 30 gives low to bot 59 and high to bot 135
51+
bot 87 gives low to bot 39 and high to bot 104
52+
bot 161 gives low to bot 173 and high to bot 125
53+
bot 104 gives low to bot 34 and high to bot 68
54+
bot 70 gives low to bot 112 and high to bot 176
55+
bot 92 gives low to bot 122 and high to bot 46
56+
bot 148 gives low to bot 28 and high to bot 58
57+
bot 49 gives low to output 0 and high to bot 33
58+
bot 140 gives low to bot 136 and high to bot 134
59+
bot 16 gives low to bot 170 and high to bot 79
60+
bot 13 gives low to bot 204 and high to bot 22
61+
bot 189 gives low to bot 148 and high to bot 45
62+
bot 89 gives low to bot 73 and high to bot 86
63+
value 31 goes to bot 50
64+
bot 166 gives low to bot 199 and high to bot 76
65+
bot 178 gives low to output 5 and high to bot 159
66+
bot 58 gives low to bot 167 and high to bot 126
67+
bot 149 gives low to bot 180 and high to bot 153
68+
bot 131 gives low to bot 97 and high to bot 66
69+
bot 64 gives low to bot 192 and high to bot 44
70+
bot 117 gives low to bot 140 and high to bot 134
71+
bot 156 gives low to bot 174 and high to bot 154
72+
value 11 goes to bot 19
73+
bot 1 gives low to bot 26 and high to bot 144
74+
bot 171 gives low to output 7 and high to bot 150
75+
bot 31 gives low to bot 110 and high to bot 127
76+
value 5 goes to bot 162
77+
bot 9 gives low to bot 8 and high to bot 128
78+
bot 93 gives low to bot 109 and high to bot 188
79+
value 47 goes to bot 184
80+
bot 80 gives low to output 19 and high to bot 42
81+
bot 155 gives low to bot 149 and high to bot 52
82+
bot 108 gives low to output 14 and high to bot 47
83+
bot 165 gives low to bot 200 and high to bot 141
84+
bot 184 gives low to bot 162 and high to bot 20
85+
bot 50 gives low to bot 143 and high to bot 4
86+
bot 28 gives low to bot 80 and high to bot 167
87+
bot 66 gives low to bot 151 and high to bot 55
88+
bot 201 gives low to bot 124 and high to bot 41
89+
bot 204 gives low to bot 94 and high to bot 56
90+
bot 134 gives low to bot 152 and high to bot 203
91+
bot 51 gives low to bot 36 and high to bot 142
92+
bot 2 gives low to bot 52 and high to bot 201
93+
bot 183 gives low to bot 38 and high to bot 78
94+
bot 26 gives low to bot 142 and high to bot 69
95+
bot 182 gives low to bot 3 and high to bot 105
96+
bot 72 gives low to bot 79 and high to bot 209
97+
bot 8 gives low to bot 185 and high to bot 65
98+
bot 75 gives low to bot 46 and high to bot 87
99+
bot 38 gives low to bot 82 and high to bot 177
100+
bot 147 gives low to bot 159 and high to bot 207
101+
bot 195 gives low to bot 104 and high to bot 119
102+
bot 63 gives low to bot 126 and high to bot 172
103+
bot 144 gives low to bot 69 and high to bot 82
104+
bot 83 gives low to output 3 and high to bot 115
105+
bot 43 gives low to bot 194 and high to bot 91
106+
value 37 goes to bot 8
107+
bot 82 gives low to bot 193 and high to bot 31
108+
bot 150 gives low to output 18 and high to bot 49
109+
value 23 goes to bot 182
110+
bot 67 gives low to bot 61 and high to bot 165
111+
bot 77 gives low to bot 107 and high to bot 122
112+
bot 130 gives low to bot 141 and high to bot 30
113+
value 73 goes to bot 12
114+
bot 41 gives low to bot 99 and high to bot 208
115+
bot 170 gives low to bot 131 and high to bot 6
116+
bot 120 gives low to bot 195 and high to bot 132
117+
bot 118 gives low to bot 47 and high to bot 129
118+
bot 100 gives low to bot 150 and high to bot 163
119+
value 67 goes to bot 185
120+
bot 152 gives low to bot 76 and high to bot 203
121+
bot 162 gives low to bot 67 and high to bot 205
122+
value 7 goes to bot 32
123+
bot 121 gives low to bot 172 and high to bot 158
124+
bot 65 gives low to bot 57 and high to bot 5
125+
bot 122 gives low to bot 81 and high to bot 74
126+
bot 21 gives low to bot 13 and high to bot 17
127+
bot 23 gives low to bot 133 and high to bot 1
128+
bot 36 gives low to bot 201 and high to bot 114
129+
bot 138 gives low to bot 160 and high to bot 131
130+
bot 55 gives low to bot 164 and high to bot 148
131+
bot 123 gives low to bot 70 and high to bot 176
132+
value 61 goes to bot 61
133+
bot 107 gives low to bot 17 and high to bot 81
134+
bot 19 gives low to bot 60 and high to bot 156
135+
value 41 goes to bot 12
136+
value 29 goes to bot 18
137+
value 13 goes to bot 60
138+
bot 62 gives low to bot 20 and high to bot 64
139+
bot 40 gives low to bot 87 and high to bot 195
140+
bot 90 gives low to bot 64 and high to bot 112
141+
bot 69 gives low to bot 71 and high to bot 193
142+
bot 35 gives low to output 4 and high to bot 108
143+
bot 177 gives low to bot 31 and high to bot 113
144+
bot 59 gives low to bot 93 and high to bot 27
145+
bot 187 gives low to bot 89 and high to bot 94
146+
bot 73 gives low to output 9 and high to bot 102
147+
bot 45 gives low to bot 58 and high to bot 63
148+
bot 39 gives low to bot 23 and high to bot 34
149+
bot 110 gives low to bot 72 and high to bot 190
150+
bot 181 gives low to bot 15 and high to bot 93
151+
bot 95 gives low to bot 7 and high to bot 15
152+
bot 33 gives low to output 13 and high to bot 169
153+
bot 20 gives low to bot 205 and high to bot 192
154+
bot 158 gives low to bot 85 and high to bot 29
155+
bot 61 gives low to bot 14 and high to bot 200
156+
value 71 goes to bot 103
157+
bot 192 gives low to bot 130 and high to bot 175
158+
bot 112 gives low to bot 44 and high to bot 139
159+
bot 96 gives low to bot 144 and high to bot 38
160+
bot 32 gives low to output 11 and high to bot 73
161+
bot 180 gives low to output 10 and high to bot 171
162+
value 59 goes to bot 3
163+
bot 208 gives low to bot 138 and high to bot 170
164+
bot 198 gives low to bot 184 and high to bot 62
165+
bot 207 gives low to output 16 and high to output 8
166+
bot 196 gives low to bot 43 and high to bot 91
167+
bot 10 gives low to bot 111 and high to bot 133
168+
bot 168 gives low to bot 35 and high to bot 202
169+
bot 113 gives low to bot 127 and high to bot 196
170+
bot 169 gives low to output 20 and high to bot 83
171+
bot 3 gives low to bot 18 and high to bot 187
172+
bot 52 gives low to bot 153 and high to bot 124
173+
bot 190 gives low to bot 209 and high to bot 43
174+
bot 125 gives low to bot 2 and high to bot 36
175+
bot 173 gives low to bot 155 and high to bot 2
176+
bot 153 gives low to bot 171 and high to bot 100
177+
bot 34 gives low to bot 1 and high to bot 96
178+
bot 84 gives low to bot 90 and high to bot 70
179+
bot 12 gives low to bot 9 and high to bot 128
180+
bot 24 gives low to bot 154 and high to bot 77
181+
bot 179 gives low to bot 63 and high to bot 121
182+
bot 85 gives low to bot 118 and high to bot 29
183+
bot 11 gives low to bot 189 and high to bot 145
184+
bot 116 gives low to bot 55 and high to bot 189
185+
bot 132 gives low to bot 119 and high to bot 53
186+
bot 15 gives low to bot 24 and high to bot 109
187+
bot 102 gives low to output 15 and high to bot 197
188+
value 43 goes to bot 206
189+
bot 37 gives low to bot 145 and high to bot 25
190+
bot 53 gives low to bot 183 and high to bot 78
191+
bot 197 gives low to output 12 and high to bot 180
192+
bot 47 gives low to output 17 and high to bot 178
193+
bot 17 gives low to bot 22 and high to bot 54
194+
bot 56 gives low to bot 106 and high to bot 173
195+
bot 191 gives low to bot 135 and high to bot 136
196+
bot 127 gives low to bot 190 and high to bot 196
197+
bot 172 gives low to bot 137 and high to bot 158
198+
bot 4 gives low to bot 146 and high to bot 84
199+
bot 42 gives low to output 6 and high to bot 35
200+
bot 145 gives low to bot 45 and high to bot 179
201+
bot 133 gives low to bot 51 and high to bot 26
202+
bot 139 gives low to bot 88 and high to bot 117
203+
bot 105 gives low to bot 187 and high to bot 204
204+
bot 126 gives low to bot 168 and high to bot 137
205+
bot 128 gives low to bot 65 and high to bot 5
206+
bot 114 gives low to bot 41 and high to bot 98
207+
bot 14 gives low to bot 206 and high to bot 95
208+
bot 91 gives low to bot 37 and high to bot 25
209+
bot 206 gives low to bot 19 and high to bot 7
210+
value 19 goes to bot 14
211+
bot 185 gives low to bot 50 and high to bot 57
212+
bot 205 gives low to bot 165 and high to bot 130
213+
bot 109 gives low to bot 77 and high to bot 92
214+
bot 175 gives low to bot 30 and high to bot 191
215+
bot 29 gives low to bot 129 and high to bot 147
216+
bot 74 gives low to bot 10 and high to bot 23
217+
bot 94 gives low to bot 86 and high to bot 106
218+
bot 25 gives low to bot 179 and high to bot 121
219+
bot 71 gives low to bot 98 and high to bot 101
220+
bot 209 gives low to bot 157 and high to bot 194
221+
bot 88 gives low to bot 191 and high to bot 140
222+
bot 124 gives low to bot 100 and high to bot 99
223+
bot 97 gives low to bot 169 and high to bot 151
224+
bot 141 gives low to bot 181 and high to bot 59
225+
bot 146 gives low to bot 62 and high to bot 90
226+
bot 200 gives low to bot 95 and high to bot 181
227+
bot 79 gives low to bot 6 and high to bot 157
228+
bot 48 gives low to bot 197 and high to bot 149
229+
value 3 goes to bot 67
230+
bot 68 gives low to bot 96 and high to bot 183
231+
bot 111 gives low to bot 125 and high to bot 51

‎2016/day10/run.py‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#! /usr/bin/env python3
2+
3+
def load_data(filename):
4+
with open(filename, 'r') as f:
5+
for line in f:
6+
line = line.rstrip('\n')
7+
yield Input.parse(line) or GivesLowHigh.parse(line)
8+
9+
class Base:
10+
@classmethod
11+
def parse(cls, s):
12+
match = re.match(cls.pattern, s)
13+
if match:
14+
return cls(match)
15+
else:
16+
return None
17+
18+
def __repr__(self):
19+
return f'{self.__class__.__name__}'
20+
21+
class Input(Base):
22+
pattern = r'^value (?P<value>\d+) goes to bot (?P<bot>\d+)$'
23+
24+
def __init__(self, match):
25+
self.bot = int(match.group('bot'))
26+
self.value = int(match.group('value'))
27+
28+
class GivesLowHigh(Base):
29+
pattern = r'^bot (?P<bot>\d+) gives low to (?P<low_type>bot|output) (?P<low_id>\d+) and high to (?P<high_type>bot|output) (?P<high_id>\d+)$'
30+
31+
def __init__(self, match):
32+
self.bot = int(match.group('bot'))
33+
self.low_type = match.group('low_type')
34+
self.low_id = int(match.group('low_id'))
35+
self.high_type = match.group('high_type')
36+
self.high_id = int(match.group('high_id'))
37+
38+
class State:
39+
def __init__(self):
40+
self.bots = {}
41+
self.bots_with_two_values = set()
42+
self.instructions = {}
43+
self.outputs = {}
44+
45+
def add_bot_value(self, bot, value):
46+
if bot not in self.bots:
47+
self.bots[bot] = [value]
48+
else:
49+
assert len(self.bots[bot]) == 1
50+
if value < self.bots[bot][0]:
51+
self.bots[bot].insert(0, value)
52+
else:
53+
self.bots[bot].append(value)
54+
self.bots_with_two_values.add(bot)
55+
56+
def add_value(self, type, id, value):
57+
if type == 'bot':
58+
self.add_bot_value(id, value)
59+
else:
60+
self.outputs[id] = value
61+
62+
def remove_bot_values(self, bot):
63+
del self.bots[bot]
64+
self.bots_with_two_values.remove(bot)
65+
66+
def add_ins(self, ins):
67+
if type(ins) is Input:
68+
self.add_bot_value(ins.bot, ins.value)
69+
elif type(ins) is GivesLowHigh:
70+
self.instructions[ins.bot] = ins
71+
72+
def run(self, hook):
73+
while self.bots_with_two_values:
74+
bot = next(iter(self.bots_with_two_values))
75+
ins = self.instructions[bot]
76+
value_low, value_high = self.bots[bot]
77+
hook(ins.bot, value_low, value_high)
78+
self.remove_bot_values(bot)
79+
self.add_value(ins.low_type, ins.low_id, value_low)
80+
self.add_value(ins.high_type, ins.high_id, value_high)
81+
82+
# Part One
83+
84+
import re
85+
86+
s = State()
87+
88+
for ins in load_data('input.txt'):
89+
s.add_ins(ins)
90+
91+
def hook(bot, value_low, value_high):
92+
if value_low == 17 and value_high == 61:
93+
print(bot)
94+
95+
s.run(hook)
96+
97+
# Part Two
98+
99+
print(s.outputs[0] * s.outputs[1] * s.outputs[2])
100+

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
```
22
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
33
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
4-
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
4+
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
55
2017 ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
66
2018 ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
77
2019 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- ++ ++ -- +- ++ +- -

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /