Skip to content

Commit 7fb2635

Browse files
committed
Year 2016 Day 10
1 parent 5d606bf commit 7fb2635

File tree

8 files changed

+330
-0
lines changed

8 files changed

+330
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ pie
252252
| 7 | [Internet Protocol Version 7](https://adventofcode.com/2016/day/7) | [Source](src/year2016/day07.rs) | 354 |
253253
| 8 | [Two-Factor Authentication](https://adventofcode.com/2016/day/8) | [Source](src/year2016/day08.rs) | 10 |
254254
| 9 | [Explosives in Cyberspace](https://adventofcode.com/2016/day/9) | [Source](src/year2016/day09.rs) | 6 |
255+
| 10 | [Balance Bots](https://adventofcode.com/2016/day/10) | [Source](src/year2016/day10.rs) | 17 |
255256

256257
## 2015
257258

benches/benchmark.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod year2016 {
7373
benchmark!(year2016, day07);
7474
benchmark!(year2016, day08);
7575
benchmark!(year2016, day09);
76+
benchmark!(year2016, day10);
7677
}
7778

7879
mod year2019 {

input/year2016/day10.txt

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

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ pub mod year2016 {
198198
pub mod day07;
199199
pub mod day08;
200200
pub mod day09;
201+
pub mod day10;
201202
}
202203

203204
/// # Rescue Santa from deep space with a solar system adventure.

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ fn all_solutions() -> Vec<Solution> {
111111
solution!(year2016, day07),
112112
solution!(year2016, day08),
113113
solution!(year2016, day09),
114+
solution!(year2016, day10),
114115
// 2019
115116
solution!(year2019, day01),
116117
solution!(year2019, day02),

src/year2016/day10.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//! # Balance Bots
2+
//!
3+
//! Performs a [topological sort](https://en.wikipedia.org/wiki/Topological_sorting) of the bots,
4+
//! starting from raw values, passing through some number of bots then ending in an output.
5+
//!
6+
//! We maintain a [`VecDeque`] of chips and destinations starting with raw inputs.
7+
//! Once each robot receives 2 chips then its low and high outputs are added to the queue.
8+
//!
9+
//! As a minor optimization we only need to store the product of outputs 0, 1 and 2.
10+
use crate::util::hash::*;
11+
use crate::util::parse::*;
12+
use std::collections::VecDeque;
13+
14+
type Input = (u32, u32);
15+
type Dest<'a> = (&'a str, &'a str);
16+
17+
struct Bot<'a> {
18+
low: Dest<'a>,
19+
high: Dest<'a>,
20+
chips: [u32; 2],
21+
amount: usize,
22+
}
23+
24+
pub fn parse(input: &str) -> Input {
25+
let tokens: Vec<_> = input.split_ascii_whitespace().collect();
26+
let mut tokens = &tokens[..];
27+
28+
let mut todo = VecDeque::new();
29+
let mut bots = FastMap::new();
30+
31+
let mut part_one = u32::MAX;
32+
let mut part_two = 1;
33+
34+
while !tokens.is_empty() {
35+
if tokens[0] == "value" {
36+
let value = tokens[1].unsigned();
37+
let dest = (tokens[4], tokens[5]);
38+
39+
tokens = &tokens[6..];
40+
todo.push_back((dest, value));
41+
} else {
42+
let key = tokens[1].unsigned();
43+
let low = (tokens[5], tokens[6]);
44+
let high = (tokens[10], tokens[11]);
45+
46+
tokens = &tokens[12..];
47+
bots.insert(key, Bot { low, high, chips: [0; 2], amount: 0 });
48+
}
49+
}
50+
51+
while let Some(((kind, index), value)) = todo.pop_front() {
52+
let index = index.unsigned();
53+
54+
if kind == "bot" {
55+
bots.entry(index).and_modify(|bot| {
56+
bot.chips[bot.amount] = value;
57+
bot.amount += 1;
58+
59+
if bot.amount == 2 {
60+
let min = bot.chips[0].min(bot.chips[1]);
61+
let max = bot.chips[0].max(bot.chips[1]);
62+
63+
todo.push_back((bot.low, min));
64+
todo.push_back((bot.high, max));
65+
66+
if min == 17 && max == 61 {
67+
part_one = index;
68+
}
69+
}
70+
});
71+
} else if index <= 2 {
72+
part_two *= value;
73+
}
74+
}
75+
76+
(part_one, part_two)
77+
}
78+
79+
pub fn part1(input: &Input) -> u32 {
80+
input.0
81+
}
82+
83+
pub fn part2(input: &Input) -> u32 {
84+
input.1
85+
}

tests/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ mod year2016 {
6666
mod day07_test;
6767
mod day08_test;
6868
mod day09_test;
69+
mod day10_test;
6970
}
7071

7172
mod year2019 {

tests/year2016/day10_test.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[test]
2+
fn part1_test() {
3+
// No example data
4+
}
5+
6+
#[test]
7+
fn part2_test() {
8+
// No example data
9+
}

0 commit comments

Comments
 (0)