Skip to content

Commit

Permalink
Year 2016: Day 07+08
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleaves committed Mar 16, 2024
1 parent 54e2508 commit aff738f
Show file tree
Hide file tree
Showing 10 changed files with 2,476 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Of note:
- The changelog 2015.5.2 has been rewritten from each commit content.
- This file may be amended entirely in the future to adhere to the [GNU Changelog style](https://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html#Style-of-Change-Logs)

## [2016.8.1]
### Added
- Solved [exercice for 2016, day 07](src/year_2016/day_07.rs).
- Solved [exercice for 2016, day 08](src/year_2016/day_08.rs).

## [2016.6.1]
### Added
- Solved [exercice for 2016, day 06](src/year_2016/day_06.rs).
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "advent-rs"
version = "2016.6.1"
version = "2016.8.1"
edition = "2021"
authors = ["Arnaud 'red' Rouyer"]
readme = "README.md"
Expand Down
10 changes: 10 additions & 0 deletions NOTES_2016.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ For efficiency purposes, the [MD5 crate that I am using](https://crates.io/crate
## Day 06: Signals and Noise

Playing with specific types for closures can be a pain, but it's often very funny to understand how things work under the hood.

## Day 07: Internet Protocol Version 7

Some iterators are annoying, but sometimes, like when calculating whethere there is an interesection of two sets, it's great to not generate the whole intersection and just peek at the first element.

## Day 08: Two-Factor Authentication

I wouldn't call it an "object model", but I like the way Rust works with `impl X for Y`.

Also, remember the [`splice()` method](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.splice), it's very useful to replace large parts of a vector at once.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ As I said, [Consistency is hard](https://github.com/joshleaves/advent-rb), and I

I'm also adding notes that may be useful if you're (like me) discovering Rust:
- [2015, complete!](NOTES_2015.md)
- [2016, up to day 04](NOTES_2016.md)
- [2016, up to day 08](NOTES_2016.md)

# Regarding style rules
I'm gonna use a mix of what `cargo fmt` does, with some stuff that feels more natural to me.
Expand Down
30 changes: 29 additions & 1 deletion benches/year_2016.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use advent_rs::year_2016::day_03;
use advent_rs::year_2016::day_04;
use advent_rs::year_2016::day_05;
use advent_rs::year_2016::day_06;
use advent_rs::year_2016::day_07;
use advent_rs::year_2016::day_08;
use criterion::{black_box, criterion_group, criterion_main, Criterion};

pub fn year_2016_day_01(c: &mut Criterion) {
Expand Down Expand Up @@ -78,13 +80,39 @@ pub fn year_2016_day_06(c: &mut Criterion) {
g2016_day_06.finish();
}

pub fn year_2016_day_07(c: &mut Criterion) {
let mut g2016_day_07 = c.benchmark_group("year_2016::day_07");
let input_year_2016_day_07 = include_str!("../inputs/year_2016/day_07_input");
g2016_day_07.bench_function("year_2016::day_07_v1", |b| {
b.iter(|| day_07::day_07_v1(black_box(input_year_2016_day_07)))
});
g2016_day_07.bench_function("year_2016::day_07_v2", |b| {
b.iter(|| day_07::day_07_v2(black_box(input_year_2016_day_07)))
});
g2016_day_07.finish();
}

pub fn year_2016_day_08(c: &mut Criterion) {
let mut g2016_day_08 = c.benchmark_group("year_2016::day_08");
let input_year_2016_day_08 = include_str!("../inputs/year_2016/day_08_input");
g2016_day_08.bench_function("year_2016::day_08_v1", |b| {
b.iter(|| day_08::day_08_v1(black_box(input_year_2016_day_08)))
});
g2016_day_08.bench_function("year_2016::day_08_v2", |b| {
b.iter(|| day_08::day_08_v2(black_box(input_year_2016_day_08)))
});
g2016_day_08.finish();
}

criterion_group!(
benches,
year_2016_day_01,
year_2016_day_02,
year_2016_day_03,
year_2016_day_04,
year_2016_day_05,
year_2016_day_06
year_2016_day_06,
year_2016_day_07,
year_2016_day_08
);
criterion_main!(benches);
2,000 changes: 2,000 additions & 0 deletions inputs/year_2016/day_07_input

Large diffs are not rendered by default.

170 changes: 170 additions & 0 deletions inputs/year_2016/day_08_input
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
rect 1x1
rotate row y=0 by 5
rect 1x1
rotate row y=0 by 5
rect 1x1
rotate row y=0 by 3
rect 1x1
rotate row y=0 by 2
rect 1x1
rotate row y=0 by 3
rect 1x1
rotate row y=0 by 2
rect 1x1
rotate row y=0 by 5
rect 1x1
rotate row y=0 by 5
rect 1x1
rotate row y=0 by 3
rect 1x1
rotate row y=0 by 2
rect 1x1
rotate row y=0 by 3
rect 2x1
rotate row y=0 by 2
rect 1x2
rotate row y=1 by 5
rotate row y=0 by 3
rect 1x2
rotate column x=30 by 1
rotate column x=25 by 1
rotate column x=10 by 1
rotate row y=1 by 5
rotate row y=0 by 2
rect 1x2
rotate row y=0 by 5
rotate column x=0 by 1
rect 4x1
rotate row y=2 by 18
rotate row y=0 by 5
rotate column x=0 by 1
rect 3x1
rotate row y=2 by 12
rotate row y=0 by 5
rotate column x=0 by 1
rect 4x1
rotate column x=20 by 1
rotate row y=2 by 5
rotate row y=0 by 5
rotate column x=0 by 1
rect 4x1
rotate row y=2 by 15
rotate row y=0 by 15
rotate column x=10 by 1
rotate column x=5 by 1
rotate column x=0 by 1
rect 14x1
rotate column x=37 by 1
rotate column x=23 by 1
rotate column x=7 by 2
rotate row y=3 by 20
rotate row y=0 by 5
rotate column x=0 by 1
rect 4x1
rotate row y=3 by 5
rotate row y=2 by 2
rotate row y=1 by 4
rotate row y=0 by 4
rect 1x4
rotate column x=35 by 3
rotate column x=18 by 3
rotate column x=13 by 3
rotate row y=3 by 5
rotate row y=2 by 3
rotate row y=1 by 1
rotate row y=0 by 1
rect 1x5
rotate row y=4 by 20
rotate row y=3 by 10
rotate row y=2 by 13
rotate row y=0 by 10
rotate column x=5 by 1
rotate column x=3 by 3
rotate column x=2 by 1
rotate column x=1 by 1
rotate column x=0 by 1
rect 9x1
rotate row y=4 by 10
rotate row y=3 by 10
rotate row y=1 by 10
rotate row y=0 by 10
rotate column x=7 by 2
rotate column x=5 by 1
rotate column x=2 by 1
rotate column x=1 by 1
rotate column x=0 by 1
rect 9x1
rotate row y=4 by 20
rotate row y=3 by 12
rotate row y=1 by 15
rotate row y=0 by 10
rotate column x=8 by 2
rotate column x=7 by 1
rotate column x=6 by 2
rotate column x=5 by 1
rotate column x=3 by 1
rotate column x=2 by 1
rotate column x=1 by 1
rotate column x=0 by 1
rect 9x1
rotate column x=46 by 2
rotate column x=43 by 2
rotate column x=24 by 2
rotate column x=14 by 3
rotate row y=5 by 15
rotate row y=4 by 10
rotate row y=3 by 3
rotate row y=2 by 37
rotate row y=1 by 10
rotate row y=0 by 5
rotate column x=0 by 3
rect 3x3
rotate row y=5 by 15
rotate row y=3 by 10
rotate row y=2 by 10
rotate row y=0 by 10
rotate column x=7 by 3
rotate column x=6 by 3
rotate column x=5 by 1
rotate column x=3 by 1
rotate column x=2 by 1
rotate column x=1 by 1
rotate column x=0 by 1
rect 9x1
rotate column x=19 by 1
rotate column x=10 by 3
rotate column x=5 by 4
rotate row y=5 by 5
rotate row y=4 by 5
rotate row y=3 by 40
rotate row y=2 by 35
rotate row y=1 by 15
rotate row y=0 by 30
rotate column x=48 by 4
rotate column x=47 by 3
rotate column x=46 by 3
rotate column x=45 by 1
rotate column x=43 by 1
rotate column x=42 by 5
rotate column x=41 by 5
rotate column x=40 by 1
rotate column x=33 by 2
rotate column x=32 by 3
rotate column x=31 by 2
rotate column x=28 by 1
rotate column x=27 by 5
rotate column x=26 by 5
rotate column x=25 by 1
rotate column x=23 by 5
rotate column x=22 by 5
rotate column x=21 by 5
rotate column x=18 by 5
rotate column x=17 by 5
rotate column x=16 by 5
rotate column x=13 by 5
rotate column x=12 by 5
rotate column x=11 by 5
rotate column x=3 by 1
rotate column x=2 by 5
rotate column x=1 by 5
rotate column x=0 by 1
24 changes: 24 additions & 0 deletions src/year_2016.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub mod day_03;
pub mod day_04;
pub mod day_05;
pub mod day_06;
pub mod day_07;
pub mod day_08;

pub fn solve(day: u8, part: u8, input: impl Into<String>) -> Option<String> {
if part != 1 && part != 2 {
Expand All @@ -20,6 +22,8 @@ pub fn solve(day: u8, part: u8, input: impl Into<String>) -> Option<String> {
4 => Some(format!("{}", day_04::day_04(part, input))),
5 => Some(format!("{}", day_05::day_05(part, input))),
6 => Some(format!("{}", day_06::day_06(part, input))),
7 => Some(format!("{}", day_07::day_07(part, input))),
8 => Some(format!("{}", day_08::day_08(part, input))),
_ => None,
}
}
Expand Down Expand Up @@ -69,4 +73,24 @@ mod tests {
assert_eq!(day_06::day_06_v1(input), "zcreqgiv");
assert_eq!(day_06::day_06_v2(input), "pljvorrk");
}

#[test]
fn day_07() {
let input = include_str!("../inputs/year_2016/day_07_input");
assert_eq!(day_07::day_07_v1(input), 118);
assert_eq!(day_07::day_07_v2(input), 260);
}

#[test]
fn day_08() {
let input = include_str!("../inputs/year_2016/day_08_input");
assert_eq!(day_08::day_08_v1(input), 106);
const CFLELOYFCS: &str = ".##..####.#....####.#.....##..#...#####..##...###.\n\
#..#.#....#....#....#....#..#.#...##....#..#.#....\n\
#....###..#....###..#....#..#..#.#.###..#....#....\n\
#....#....#....#....#....#..#...#..#....#.....##..\n\
#..#.#....#....#....#....#..#...#..#....#..#....#.\n\
.##..#....####.####.####..##....#..#.....##..###..";
assert_eq!(day_08::day_08_v2(input), CFLELOYFCS);
}
}
Loading

0 comments on commit aff738f

Please sign in to comment.