···11+import re
22+import fileinput
33+from collections import defaultdict
44+from utils import parse_line, mul
55+66+77+BOTS = defaultdict(list)
88+OUTPUTS = defaultdict(list)
99+1010+inst = [line.strip() for line in fileinput.input()]
1111+1212+while inst:
1313+ temp = []
1414+1515+ for line in inst:
1616+ if 'value' in line:
1717+ val, bot = [int(x) for x in re.findall(r'(\d+)', line)]
1818+ BOTS[bot].append(val)
1919+2020+ else:
2121+ bot, low_t, low, high_t, high = parse_line(r'bot (\d+) .+ (\w+) (\d+) .+ (\w+) (\d+)', line)
2222+2323+ if bot not in BOTS or len(BOTS[bot]) != 2:
2424+ temp.append(line)
2525+ continue
2626+2727+ if 17 in BOTS[bot] and 61 in BOTS[bot]:
2828+ print "Bot #%i compares 17 and 61." % bot
2929+3030+ l, h = sorted(BOTS[bot][:2])
3131+ BOTS[bot] = []
3232+3333+ if low_t == 'bot':
3434+ BOTS[low].append(l)
3535+ else:
3636+ OUTPUTS[low].append(l)
3737+3838+ if high_t == 'bot':
3939+ BOTS[high].append(h)
4040+ else:
4141+ OUTPUTS[high].append(h)
4242+4343+ inst = temp
4444+ temp = []
4545+4646+product = mul(OUTPUTS[i][0] for i in range(3))
4747+print "Product of values in outputs 0-2 is %i." % product
+231
2016/input10.txt
···11+bot 147 gives low to bot 67 and high to bot 71
22+bot 142 gives low to bot 128 and high to bot 164
33+bot 47 gives low to bot 4 and high to bot 209
44+bot 107 gives low to bot 194 and high to bot 103
55+bot 102 gives low to bot 82 and high to bot 3
66+bot 101 gives low to bot 46 and high to bot 111
77+value 23 goes to bot 76
88+bot 16 gives low to bot 203 and high to bot 32
99+bot 30 gives low to output 20 and high to bot 31
1010+bot 170 gives low to bot 123 and high to bot 108
1111+value 3 goes to bot 122
1212+bot 176 gives low to bot 89 and high to bot 199
1313+value 43 goes to bot 117
1414+bot 190 gives low to bot 120 and high to bot 198
1515+bot 72 gives low to bot 14 and high to bot 37
1616+bot 122 gives low to bot 26 and high to bot 101
1717+bot 62 gives low to bot 88 and high to bot 85
1818+bot 184 gives low to bot 103 and high to bot 113
1919+bot 146 gives low to bot 47 and high to bot 7
2020+bot 133 gives low to bot 32 and high to bot 92
2121+bot 188 gives low to bot 79 and high to bot 97
2222+value 2 goes to bot 26
2323+bot 68 gives low to output 18 and high to output 5
2424+bot 139 gives low to bot 147 and high to bot 195
2525+bot 36 gives low to bot 166 and high to bot 116
2626+bot 99 gives low to bot 36 and high to bot 28
2727+bot 55 gives low to bot 134 and high to bot 182
2828+bot 132 gives low to bot 20 and high to bot 201
2929+bot 81 gives low to bot 126 and high to bot 153
3030+bot 177 gives low to output 16 and high to bot 12
3131+bot 23 gives low to bot 90 and high to bot 42
3232+bot 191 gives low to bot 157 and high to bot 73
3333+bot 3 gives low to bot 25 and high to bot 186
3434+bot 126 gives low to bot 83 and high to bot 24
3535+bot 105 gives low to bot 176 and high to bot 60
3636+bot 204 gives low to bot 102 and high to bot 118
3737+bot 199 gives low to bot 141 and high to bot 83
3838+bot 194 gives low to bot 63 and high to bot 197
3939+bot 161 gives low to bot 170 and high to bot 173
4040+bot 152 gives low to bot 92 and high to bot 4
4141+bot 53 gives low to bot 52 and high to bot 205
4242+bot 171 gives low to bot 137 and high to bot 91
4343+bot 71 gives low to bot 161 and high to bot 58
4444+bot 128 gives low to bot 192 and high to bot 164
4545+bot 118 gives low to bot 3 and high to bot 57
4646+bot 124 gives low to bot 86 and high to bot 87
4747+bot 93 gives low to bot 85 and high to bot 96
4848+bot 198 gives low to bot 172 and high to bot 44
4949+bot 100 gives low to bot 124 and high to bot 78
5050+bot 145 gives low to bot 91 and high to bot 168
5151+value 47 goes to bot 120
5252+bot 165 gives low to bot 57 and high to bot 158
5353+bot 138 gives low to bot 64 and high to bot 54
5454+value 5 goes to bot 150
5555+bot 29 gives low to bot 23 and high to bot 42
5656+bot 110 gives low to output 14 and high to bot 68
5757+bot 73 gives low to bot 156 and high to bot 29
5858+bot 49 gives low to bot 0 and high to bot 202
5959+bot 32 gives low to bot 10 and high to bot 51
6060+value 11 goes to bot 36
6161+bot 131 gives low to bot 98 and high to bot 151
6262+value 31 goes to bot 105
6363+bot 135 gives low to output 4 and high to bot 30
6464+bot 185 gives low to bot 171 and high to bot 145
6565+bot 67 gives low to bot 179 and high to bot 161
6666+bot 187 gives low to bot 37 and high to bot 125
6767+value 59 goes to bot 190
6868+bot 1 gives low to bot 155 and high to bot 128
6969+bot 10 gives low to bot 181 and high to bot 27
7070+bot 13 gives low to bot 188 and high to bot 22
7171+bot 182 gives low to bot 95 and high to bot 15
7272+bot 31 gives low to output 11 and high to bot 0
7373+bot 116 gives low to bot 193 and high to bot 147
7474+bot 17 gives low to bot 9 and high to bot 90
7575+bot 205 gives low to bot 130 and high to bot 204
7676+bot 169 gives low to bot 101 and high to bot 179
7777+bot 206 gives low to bot 159 and high to bot 2
7878+bot 42 gives low to bot 18 and high to bot 55
7979+value 17 goes to bot 63
8080+bot 19 gives low to bot 109 and high to bot 132
8181+bot 172 gives low to bot 184 and high to bot 44
8282+bot 125 gives low to bot 200 and high to bot 11
8383+bot 119 gives low to bot 177 and high to bot 180
8484+bot 26 gives low to bot 105 and high to bot 46
8585+bot 2 gives low to bot 112 and high to bot 146
8686+bot 61 gives low to bot 77 and high to bot 16
8787+bot 123 gives low to bot 153 and high to bot 206
8888+bot 40 gives low to output 8 and high to bot 181
8989+bot 103 gives low to bot 197 and high to bot 191
9090+bot 34 gives low to bot 19 and high to bot 48
9191+bot 25 gives low to bot 31 and high to bot 49
9292+value 67 goes to bot 194
9393+value 13 goes to bot 59
9494+bot 8 gives low to bot 167 and high to bot 1
9595+bot 56 gives low to bot 16 and high to bot 133
9696+bot 14 gives low to output 15 and high to bot 43
9797+bot 70 gives low to bot 125 and high to bot 64
9898+bot 164 gives low to bot 94 and high to bot 165
9999+bot 150 gives low to bot 122 and high to bot 169
100100+bot 95 gives low to bot 145 and high to bot 15
101101+bot 90 gives low to bot 34 and high to bot 18
102102+bot 148 gives low to bot 54 and high to bot 8
103103+bot 113 gives low to bot 191 and high to bot 50
104104+value 53 goes to bot 119
105105+bot 77 gives low to bot 104 and high to bot 203
106106+bot 82 gives low to bot 30 and high to bot 25
107107+bot 179 gives low to bot 111 and high to bot 170
108108+bot 141 gives low to bot 180 and high to bot 61
109109+bot 173 gives low to bot 108 and high to bot 183
110110+bot 109 gives low to bot 58 and high to bot 20
111111+bot 94 gives low to bot 118 and high to bot 165
112112+bot 0 gives low to output 7 and high to bot 21
113113+bot 104 gives low to output 3 and high to bot 40
114114+value 61 goes to bot 166
115115+bot 163 gives low to bot 151 and high to bot 52
116116+bot 193 gives low to bot 169 and high to bot 67
117117+bot 60 gives low to bot 199 and high to bot 126
118118+bot 195 gives low to bot 71 and high to bot 109
119119+bot 80 gives low to bot 100 and high to bot 78
120120+bot 137 gives low to bot 45 and high to bot 208
121121+bot 155 gives low to bot 205 and high to bot 192
122122+bot 50 gives low to bot 73 and high to bot 29
123123+bot 83 gives low to bot 61 and high to bot 56
124124+bot 88 gives low to bot 72 and high to bot 187
125125+bot 151 gives low to bot 160 and high to bot 41
126126+bot 52 gives low to bot 41 and high to bot 130
127127+bot 27 gives low to bot 5 and high to bot 72
128128+bot 78 gives low to bot 87 and high to bot 106
129129+bot 98 gives low to output 17 and high to bot 160
130130+bot 201 gives low to bot 185 and high to bot 95
131131+bot 111 gives low to bot 81 and high to bot 123
132132+bot 189 gives low to bot 162 and high to bot 124
133133+bot 51 gives low to bot 27 and high to bot 88
134134+bot 197 gives low to bot 13 and high to bot 157
135135+bot 160 gives low to output 6 and high to bot 74
136136+value 19 goes to bot 176
137137+bot 134 gives low to bot 201 and high to bot 182
138138+bot 200 gives low to bot 6 and high to bot 131
139139+bot 24 gives low to bot 56 and high to bot 207
140140+value 29 goes to bot 99
141141+value 71 goes to bot 89
142142+bot 159 gives low to bot 207 and high to bot 112
143143+bot 35 gives low to bot 7 and high to bot 175
144144+bot 143 gives low to bot 195 and high to bot 19
145145+bot 91 gives low to bot 208 and high to bot 66
146146+bot 92 gives low to bot 51 and high to bot 62
147147+bot 183 gives low to bot 121 and high to bot 137
148148+bot 39 gives low to bot 189 and high to bot 100
149149+bot 66 gives low to bot 84 and high to bot 140
150150+bot 112 gives low to bot 152 and high to bot 47
151151+bot 181 gives low to output 12 and high to bot 5
152152+bot 208 gives low to bot 35 and high to bot 84
153153+value 41 goes to bot 190
154154+bot 57 gives low to bot 186 and high to bot 158
155155+bot 41 gives low to bot 74 and high to bot 65
156156+bot 96 gives low to bot 70 and high to bot 138
157157+bot 74 gives low to output 2 and high to bot 135
158158+bot 4 gives low to bot 62 and high to bot 93
159159+bot 156 gives low to bot 17 and high to bot 23
160160+bot 6 gives low to output 9 and high to bot 98
161161+bot 65 gives low to bot 135 and high to bot 82
162162+bot 64 gives low to bot 11 and high to bot 149
163163+bot 45 gives low to bot 146 and high to bot 35
164164+bot 28 gives low to bot 116 and high to bot 139
165165+bot 149 gives low to bot 163 and high to bot 53
166166+bot 136 gives low to bot 96 and high to bot 127
167167+bot 48 gives low to bot 132 and high to bot 134
168168+bot 192 gives low to bot 204 and high to bot 94
169169+bot 166 gives low to bot 150 and high to bot 193
170170+bot 174 gives low to bot 129 and high to bot 69
171171+bot 18 gives low to bot 48 and high to bot 55
172172+bot 76 gives low to bot 115 and high to bot 172
173173+bot 108 gives low to bot 206 and high to bot 121
174174+bot 79 gives low to bot 28 and high to bot 38
175175+bot 97 gives low to bot 38 and high to bot 9
176176+bot 15 gives low to bot 168 and high to bot 114
177177+bot 37 gives low to bot 43 and high to bot 200
178178+bot 175 gives low to bot 75 and high to bot 189
179179+bot 84 gives low to bot 175 and high to bot 39
180180+bot 162 gives low to bot 127 and high to bot 86
181181+bot 167 gives low to bot 53 and high to bot 155
182182+bot 168 gives low to bot 66 and high to bot 114
183183+bot 129 gives low to bot 144 and high to bot 69
184184+bot 89 gives low to bot 119 and high to bot 141
185185+bot 69 gives low to bot 110 and high to bot 68
186186+bot 130 gives low to bot 65 and high to bot 102
187187+bot 5 gives low to output 19 and high to bot 14
188188+bot 54 gives low to bot 149 and high to bot 167
189189+bot 127 gives low to bot 138 and high to bot 148
190190+bot 153 gives low to bot 24 and high to bot 159
191191+bot 117 gives low to bot 59 and high to bot 188
192192+bot 144 gives low to output 1 and high to bot 110
193193+bot 63 gives low to bot 117 and high to bot 13
194194+bot 44 gives low to bot 113 and high to bot 50
195195+bot 114 gives low to bot 140 and high to bot 80
196196+bot 115 gives low to bot 107 and high to bot 184
197197+bot 207 gives low to bot 133 and high to bot 152
198198+bot 33 gives low to bot 8 and high to bot 196
199199+bot 59 gives low to bot 99 and high to bot 79
200200+bot 140 gives low to bot 39 and high to bot 80
201201+bot 202 gives low to bot 21 and high to bot 129
202202+value 7 goes to bot 107
203203+bot 11 gives low to bot 131 and high to bot 163
204204+bot 21 gives low to output 0 and high to bot 144
205205+bot 106 gives low to bot 196 and high to bot 142
206206+bot 121 gives low to bot 2 and high to bot 45
207207+bot 154 gives low to bot 183 and high to bot 171
208208+bot 157 gives low to bot 22 and high to bot 156
209209+bot 203 gives low to bot 40 and high to bot 10
210210+bot 12 gives low to output 10 and high to bot 104
211211+bot 186 gives low to bot 49 and high to bot 178
212212+bot 43 gives low to output 13 and high to bot 6
213213+bot 196 gives low to bot 1 and high to bot 142
214214+bot 22 gives low to bot 97 and high to bot 17
215215+bot 38 gives low to bot 139 and high to bot 143
216216+bot 209 gives low to bot 93 and high to bot 136
217217+bot 9 gives low to bot 143 and high to bot 34
218218+bot 180 gives low to bot 12 and high to bot 77
219219+bot 7 gives low to bot 209 and high to bot 75
220220+value 37 goes to bot 115
221221+bot 120 gives low to bot 76 and high to bot 198
222222+bot 75 gives low to bot 136 and high to bot 162
223223+bot 20 gives low to bot 154 and high to bot 185
224224+bot 178 gives low to bot 202 and high to bot 174
225225+bot 86 gives low to bot 148 and high to bot 33
226226+value 73 goes to bot 177
227227+bot 85 gives low to bot 187 and high to bot 70
228228+bot 158 gives low to bot 178 and high to bot 174
229229+bot 46 gives low to bot 60 and high to bot 81
230230+bot 87 gives low to bot 33 and high to bot 106
231231+bot 58 gives low to bot 173 and high to bot 154