Browse Source

Day 10

master
Chris Smith 7 years ago
parent
commit
af944f531d
2 changed files with 254 additions and 0 deletions
  1. 23
    0
      10.py
  2. 231
    0
      10.txt

+ 23
- 0
10.py View File

@@ -0,0 +1,23 @@
1
+#!/usr/bin/python3
2
+
3
+import collections
4
+
5
+with open('10.txt', 'r') as file:
6
+    targets = collections.defaultdict(lambda: {'inputs': [], 'low': -1, 'high': -1})
7
+    lines = list(map(str.split, map(str.strip, file.readlines())))
8
+    for instr in lines:
9
+        if instr[0] == 'value':
10
+            targets[' '.join(instr[4:6])]['inputs'].append(int(instr[1]))
11
+        else:
12
+            targets[' '.join(instr[0:2])]['low'] = ' '.join(instr[5:7])
13
+            targets[' '.join(instr[0:2])]['high'] = ' '.join(instr[10:12])
14
+
15
+pending = set(targets.keys())
16
+while len(pending):
17
+    for k, bot in [(k, targets[k]) for k in pending if len(targets[k]['inputs']) == 2]:
18
+        targets[bot['low']]['inputs'].append(min(bot['inputs']))
19
+        targets[bot['high']]['inputs'].append(max(bot['inputs']))
20
+        pending.remove(k)
21
+
22
+print("Part 1: %s" % [k for k,v in targets.items() if 61 in v['inputs'] and 17 in v['inputs']][0])
23
+print("Part 2: %i" % (targets['output 0']['inputs'][0] * targets['output 1']['inputs'][0] * targets['output 2']['inputs'][0]))

+ 231
- 0
10.txt View File

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

Loading…
Cancel
Save