Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 12c9a12

Browse files
committedOct 14, 2023
Year 2016 Day 8
1 parent 7d5dd7f commit 12c9a12

File tree

8 files changed

+236
-0
lines changed

8 files changed

+236
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ pie
250250
| 5 | [How About a Nice Game of Chess?](https://adventofcode.com/2016/day/5) | [Source](src/year2016/day05.rs) | 229000 |
251251
| 6 | [Signals and Noise](https://adventofcode.com/2016/day/6) | [Source](src/year2016/day06.rs) | 5 |
252252
| 7 | [Internet Protocol Version 7](https://adventofcode.com/2016/day/7) | [Source](src/year2016/day07.rs) | 354 |
253+
| 8 | [Two-Factor Authentication](https://adventofcode.com/2016/day/8) | [Source](src/year2016/day08.rs) | 10 |
253254

254255
## 2015
255256

‎benches/benchmark.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ mod year2016 {
7171
benchmark!(year2016, day05);
7272
benchmark!(year2016, day06);
7373
benchmark!(year2016, day07);
74+
benchmark!(year2016, day08);
7475
}
7576

7677
mod year2019 {

‎input/year2016/day08.txt

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
rect 1x1
2+
rotate row y=0 by 6
3+
rect 1x1
4+
rotate row y=0 by 3
5+
rect 1x1
6+
rotate row y=0 by 5
7+
rect 1x1
8+
rotate row y=0 by 4
9+
rect 2x1
10+
rotate row y=0 by 5
11+
rect 2x1
12+
rotate row y=0 by 2
13+
rect 1x1
14+
rotate row y=0 by 5
15+
rect 4x1
16+
rotate row y=0 by 2
17+
rect 1x1
18+
rotate row y=0 by 3
19+
rect 1x1
20+
rotate row y=0 by 3
21+
rect 1x1
22+
rotate row y=0 by 2
23+
rect 1x1
24+
rotate row y=0 by 6
25+
rect 4x1
26+
rotate row y=0 by 4
27+
rotate column x=0 by 1
28+
rect 3x1
29+
rotate row y=0 by 6
30+
rotate column x=0 by 1
31+
rect 4x1
32+
rotate column x=10 by 1
33+
rotate row y=2 by 16
34+
rotate row y=0 by 8
35+
rotate column x=5 by 1
36+
rotate column x=0 by 1
37+
rect 7x1
38+
rotate column x=37 by 1
39+
rotate column x=21 by 2
40+
rotate column x=15 by 1
41+
rotate column x=11 by 2
42+
rotate row y=2 by 39
43+
rotate row y=0 by 36
44+
rotate column x=33 by 2
45+
rotate column x=32 by 1
46+
rotate column x=28 by 2
47+
rotate column x=27 by 1
48+
rotate column x=25 by 1
49+
rotate column x=22 by 1
50+
rotate column x=21 by 2
51+
rotate column x=20 by 3
52+
rotate column x=18 by 1
53+
rotate column x=15 by 2
54+
rotate column x=12 by 1
55+
rotate column x=10 by 1
56+
rotate column x=6 by 2
57+
rotate column x=5 by 1
58+
rotate column x=2 by 1
59+
rotate column x=0 by 1
60+
rect 35x1
61+
rotate column x=45 by 1
62+
rotate row y=1 by 28
63+
rotate column x=38 by 2
64+
rotate column x=33 by 1
65+
rotate column x=28 by 1
66+
rotate column x=23 by 1
67+
rotate column x=18 by 1
68+
rotate column x=13 by 2
69+
rotate column x=8 by 1
70+
rotate column x=3 by 1
71+
rotate row y=3 by 2
72+
rotate row y=2 by 2
73+
rotate row y=1 by 5
74+
rotate row y=0 by 1
75+
rect 1x5
76+
rotate column x=43 by 1
77+
rotate column x=31 by 1
78+
rotate row y=4 by 35
79+
rotate row y=3 by 20
80+
rotate row y=1 by 27
81+
rotate row y=0 by 20
82+
rotate column x=17 by 1
83+
rotate column x=15 by 1
84+
rotate column x=12 by 1
85+
rotate column x=11 by 2
86+
rotate column x=10 by 1
87+
rotate column x=8 by 1
88+
rotate column x=7 by 1
89+
rotate column x=5 by 1
90+
rotate column x=3 by 2
91+
rotate column x=2 by 1
92+
rotate column x=0 by 1
93+
rect 19x1
94+
rotate column x=20 by 3
95+
rotate column x=14 by 1
96+
rotate column x=9 by 1
97+
rotate row y=4 by 15
98+
rotate row y=3 by 13
99+
rotate row y=2 by 15
100+
rotate row y=1 by 18
101+
rotate row y=0 by 15
102+
rotate column x=13 by 1
103+
rotate column x=12 by 1
104+
rotate column x=11 by 3
105+
rotate column x=10 by 1
106+
rotate column x=8 by 1
107+
rotate column x=7 by 1
108+
rotate column x=6 by 1
109+
rotate column x=5 by 1
110+
rotate column x=3 by 2
111+
rotate column x=2 by 1
112+
rotate column x=1 by 1
113+
rotate column x=0 by 1
114+
rect 14x1
115+
rotate row y=3 by 47
116+
rotate column x=19 by 3
117+
rotate column x=9 by 3
118+
rotate column x=4 by 3
119+
rotate row y=5 by 5
120+
rotate row y=4 by 5
121+
rotate row y=3 by 8
122+
rotate row y=1 by 5
123+
rotate column x=3 by 2
124+
rotate column x=2 by 3
125+
rotate column x=1 by 2
126+
rotate column x=0 by 2
127+
rect 4x2
128+
rotate column x=35 by 5
129+
rotate column x=20 by 3
130+
rotate column x=10 by 5
131+
rotate column x=3 by 2
132+
rotate row y=5 by 20
133+
rotate row y=3 by 30
134+
rotate row y=2 by 45
135+
rotate row y=1 by 30
136+
rotate column x=48 by 5
137+
rotate column x=47 by 5
138+
rotate column x=46 by 3
139+
rotate column x=45 by 4
140+
rotate column x=43 by 5
141+
rotate column x=42 by 5
142+
rotate column x=41 by 5
143+
rotate column x=38 by 1
144+
rotate column x=37 by 5
145+
rotate column x=36 by 5
146+
rotate column x=35 by 1
147+
rotate column x=33 by 1
148+
rotate column x=32 by 5
149+
rotate column x=31 by 5
150+
rotate column x=28 by 5
151+
rotate column x=27 by 5
152+
rotate column x=26 by 5
153+
rotate column x=17 by 5
154+
rotate column x=16 by 5
155+
rotate column x=15 by 4
156+
rotate column x=13 by 1
157+
rotate column x=12 by 5
158+
rotate column x=11 by 5
159+
rotate column x=10 by 1
160+
rotate column x=8 by 1
161+
rotate column x=2 by 5
162+
rotate column x=1 by 5

‎src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub mod year2016 {
196196
pub mod day05;
197197
pub mod day06;
198198
pub mod day07;
199+
pub mod day08;
199200
}
200201

201202
/// # 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
@@ -109,6 +109,7 @@ fn all_solutions() -> Vec<Solution> {
109109
solution!(year2016, day05),
110110
solution!(year2016, day06),
111111
solution!(year2016, day07),
112+
solution!(year2016, day08),
112113
// 2019
113114
solution!(year2019, day01),
114115
solution!(year2019, day02),

‎src/year2016/day08.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! # Two-Factor Authentication
2+
//!
3+
//! The pixels are sparse enough that's it efficient to store them as [`Point`] objects and
4+
//! manipulate individually. Pixels don't overlap so we can use a vec instead of a set to store
5+
//! distinct points without overcounting.
6+
//!
7+
//! [`Point`]: crate::util::point
8+
use crate::util::iter::*;
9+
use crate::util::parse::*;
10+
use crate::util::point::*;
11+
12+
pub fn parse(input: &str) -> Vec<Point> {
13+
let amounts = input.iter_signed::<i32>().chunk::<2>();
14+
let mut points = Vec::new();
15+
16+
for (line, [a, b]) in input.lines().zip(amounts) {
17+
if line.starts_with("rect") {
18+
for x in 0..a {
19+
for y in 0..b {
20+
points.push(Point::new(x, y));
21+
}
22+
}
23+
} else if line.starts_with("rotate row") {
24+
for point in &mut points {
25+
if point.y == a {
26+
point.x = (point.x + b) % 50;
27+
}
28+
}
29+
} else {
30+
for point in &mut points {
31+
if point.x == a {
32+
point.y = (point.y + b) % 6;
33+
}
34+
}
35+
}
36+
}
37+
38+
points
39+
}
40+
41+
pub fn part1(input: &[Point]) -> usize {
42+
input.len()
43+
}
44+
45+
pub fn part2(input: &[Point]) -> String {
46+
let width = input.iter().map(|p| p.x).max().unwrap() + 1;
47+
48+
let mut pixels = vec!['.'; width as usize * 6];
49+
for point in input {
50+
pixels[(width * point.y + point.x) as usize] = '#';
51+
}
52+
53+
let mut result = pixels
54+
.chunks_exact(width as usize)
55+
.map(|row| row.iter().collect())
56+
.collect::<Vec<String>>()
57+
.join("\n");
58+
result.insert(0, '\n');
59+
result
60+
}

‎tests/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ mod year2016 {
6464
mod day05_test;
6565
mod day06_test;
6666
mod day07_test;
67+
mod day08_test;
6768
}
6869

6970
mod year2019 {

‎tests/year2016/day08_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)
Please sign in to comment.