Skip to content

Commit

Permalink
Year 2017: Day 08+09+10+11+12
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleaves committed Mar 26, 2024
1 parent f5912f4 commit ee53f47
Show file tree
Hide file tree
Showing 17 changed files with 3,585 additions and 52 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ 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)

## [2017.12.1]
### Added
- Solved [exercice for 2017, day 08](src/year_2017/08.rs).
- Solved [exercice for 2017, day 09](src/year_2017/09.rs).
- Solved [exercice for 2017, day 10](src/year_2017/10.rs).
- Solved [exercice for 2017, day 11](src/year_2017/11.rs).
- Solved [exercice for 2017, day 12](src/year_2017/12.rs).

## [2017.7.1]
### Added
- Solved [exercice for 2017, day 06](src/year_2017/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 = "2017.7.1"
version = "2017.12.1"
edition = "2021"
authors = ["Arnaud 'red' Rouyer"]
readme = "README.md"
Expand Down
20 changes: 20 additions & 0 deletions NOTES_2017.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,23 @@ No idea why, but I cannot get this one to go faster at all.
Little-known fact about me: I hate traversing trees.

That said, you can always find ways to avoid doing it :D

## Day 08: I Heard You Like Registers

Since we only iterate once with no jumps, no need to save instructions.

## Day 09: Stream Processing

The usual: do your best to only iter every character once. Rust's pattern-matching is really good there.

## Day 10: Knot Hash

Funny exercise, the second part was A BIT confusing at first, but it got okay.

## Day 11: Hex Ed

Navigating hexagons is a pain. Naive approach is to start with "only change the Y value if we move up, not down", but this will fail you in the long run. What you can do, is treat each hexagone as "two squares": moving up means `Y minus 2` and moving down means `Y plus 2`, while all diagonals work the way they would with a regular grid.

## Day 12: Digital Plumber

I hate traversing trees. But you don't always have to.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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, complete!](NOTES_2016.md)
- [2017, up to day 07](NOTES_2017.md)
- [2017, up to day 12](NOTES_2017.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
153 changes: 131 additions & 22 deletions benches/year_2017.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,92 +5,196 @@ use advent_rs::year_2017::day_04;
use advent_rs::year_2017::day_05;
use advent_rs::year_2017::day_06;
use advent_rs::year_2017::day_07;
use advent_rs::year_2017::day_08;
use advent_rs::year_2017::day_09;
use advent_rs::year_2017::day_10;
use advent_rs::year_2017::day_11;
use advent_rs::year_2017::day_12;
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn year_2017_day_01(c: &mut Criterion) {
let mut g2017_day_01 = c.benchmark_group("year_2017::day_01");
let input_day_01 = include_str!("../inputs/year_2017/day_01_input");
assert_eq!(day_01::day_01_v1(black_box(input_day_01)), 1_069);
assert_eq!(day_01::day_01_v2(black_box(input_day_01)), 1_268);

let mut g2017_day_01 = c.benchmark_group("year_2017::day_01");
g2017_day_01.bench_function("year_2017::day_01_v1", |b| {
b.iter(|| assert_eq!(1_069, day_01::day_01_v1(black_box(input_day_01))))
b.iter(|| day_01::day_01_v1(black_box(input_day_01)))
});
g2017_day_01.bench_function("year_2017::day_01_v2", |b| {
b.iter(|| assert_eq!(1_268, day_01::day_01_v2(black_box(input_day_01))))
b.iter(|| day_01::day_01_v2(black_box(input_day_01)))
});
g2017_day_01.finish();
}

fn year_2017_day_02(c: &mut Criterion) {
let mut g2017_day_02 = c.benchmark_group("year_2017::day_02");
let input_day_02 = include_str!("../inputs/year_2017/day_02_input");
assert_eq!(day_02::day_02_v1(black_box(input_day_02)), 53_978);
assert_eq!(day_02::day_02_v2(black_box(input_day_02)), 314);

let mut g2017_day_02 = c.benchmark_group("year_2017::day_02");
g2017_day_02.bench_function("year_2017::day_02_v1", |b| {
b.iter(|| assert_eq!(53_978, day_02::day_02_v1(black_box(input_day_02))))
b.iter(|| day_02::day_02_v1(black_box(input_day_02)))
});
g2017_day_02.bench_function("year_2017::day_02_v2", |b| {
b.iter(|| assert_eq!(314, day_02::day_02_v2(black_box(input_day_02))))
b.iter(|| day_02::day_02_v2(black_box(input_day_02)))
});
g2017_day_02.finish();
}

fn year_2017_day_03(c: &mut Criterion) {
let mut g2017_day_03 = c.benchmark_group("year_2017::day_03");
let input_day_03 = include_str!("../inputs/year_2017/day_03_input");
assert_eq!(day_03::day_03_v1(black_box(input_day_03)), 552);
assert_eq!(day_03::day_03_v2(black_box(input_day_03)), 330_785);

let mut g2017_day_03 = c.benchmark_group("year_2017::day_03");
g2017_day_03.bench_function("year_2017::day_03_v1", |b| {
b.iter(|| assert_eq!(552, day_03::day_03_v1(black_box(input_day_03))))
b.iter(|| day_03::day_03_v1(black_box(input_day_03)))
});
g2017_day_03.bench_function("year_2017::day_03_v2", |b| {
b.iter(|| assert_eq!(330_785, day_03::day_03_v2(black_box(input_day_03))))
b.iter(|| day_03::day_03_v2(black_box(input_day_03)))
});
g2017_day_03.finish();
}

fn year_2017_day_04(c: &mut Criterion) {
let mut g2017_day_04 = c.benchmark_group("year_2017::day_04");
let input_day_04 = include_str!("../inputs/year_2017/day_04_input");
assert_eq!(day_04::day_04_v1(black_box(input_day_04)), 466);
assert_eq!(day_04::day_04_v2(black_box(input_day_04)), 251);

let mut g2017_day_04 = c.benchmark_group("year_2017::day_04");
g2017_day_04.bench_function("year_2017::day_04_v1", |b| {
b.iter(|| assert_eq!(466, day_04::day_04_v1(black_box(input_day_04))))
b.iter(|| day_04::day_04_v1(black_box(input_day_04)))
});
g2017_day_04.bench_function("year_2017::day_04_v2", |b| {
b.iter(|| assert_eq!(251, day_04::day_04_v2(black_box(input_day_04))))
b.iter(|| day_04::day_04_v2(black_box(input_day_04)))
});
g2017_day_04.finish();
}

fn year_2017_day_05(c: &mut Criterion) {
let mut g2017_day_05 = c.benchmark_group("year_2017::day_05");
let input_day_05 = include_str!("../inputs/year_2017/day_05_input");
assert_eq!(day_05::day_05_v1(black_box(input_day_05)), 373_160);
assert_eq!(day_05::day_05_v2(black_box(input_day_05)), 26_395_586);

let mut g2017_day_05 = c.benchmark_group("year_2017::day_05");
g2017_day_05.bench_function("year_2017::day_05_v1", |b| {
b.iter(|| assert_eq!(373_160, day_05::day_05_v1(black_box(input_day_05))))
b.iter(|| day_05::day_05_v1(black_box(input_day_05)))
});
g2017_day_05.bench_function("year_2017::day_05_v2", |b| {
b.iter(|| assert_eq!(26_395_586, day_05::day_05_v2(black_box(input_day_05))))
b.iter(|| day_05::day_05_v2(black_box(input_day_05)))
});
g2017_day_05.finish();
}

fn year_2017_day_06(c: &mut Criterion) {
let mut g2017_day_06 = c.benchmark_group("year_2017::day_06");
let input_day_06 = include_str!("../inputs/year_2017/day_06_input");
assert_eq!(day_06::day_06_v1(black_box(input_day_06)), 11_137);
assert_eq!(day_06::day_06_v2(black_box(input_day_06)), 1_037);

let mut g2017_day_06 = c.benchmark_group("year_2017::day_06");
g2017_day_06.bench_function("year_2017::day_06_v1", |b| {
b.iter(|| assert_eq!(11_137, day_06::day_06_v1(black_box(input_day_06))))
b.iter(|| day_06::day_06_v1(black_box(input_day_06)))
});
g2017_day_06.bench_function("year_2017::day_06_v2", |b| {
b.iter(|| assert_eq!(1_037, day_06::day_06_v2(black_box(input_day_06))))
b.iter(|| day_06::day_06_v2(black_box(input_day_06)))
});
g2017_day_06.finish();
}

fn year_2017_day_07(c: &mut Criterion) {
let mut g2017_day_07 = c.benchmark_group("year_2017::day_07");
let input_day_07 = include_str!("../inputs/year_2017/day_07_input");
assert_eq!(day_07::day_07_v1(black_box(input_day_07)), "ykpsek");
assert_eq!(day_07::day_07_v2(black_box(input_day_07)), "1060");

let mut g2017_day_07 = c.benchmark_group("year_2017::day_07");
g2017_day_07.bench_function("year_2017::day_07_v1", |b| {
b.iter(|| assert_eq!("ykpsek", day_07::day_07_v1(black_box(input_day_07))))
b.iter(|| day_07::day_07_v1(black_box(input_day_07)))
});
g2017_day_07.bench_function("year_2017::day_07_v2", |b| {
b.iter(|| assert_eq!("1060", day_07::day_07_v2(black_box(input_day_07))))
b.iter(|| day_07::day_07_v2(black_box(input_day_07)))
});
g2017_day_07.finish();
}

fn year_2017_day_08(c: &mut Criterion) {
let input_day_08 = include_str!("../inputs/year_2017/day_08_input");
assert_eq!(day_08::day_08_v1(black_box(input_day_08)), 4_163);
assert_eq!(day_08::day_08_v2(black_box(input_day_08)), 5_347);

let mut g2017_day_08 = c.benchmark_group("year_2017::day_08");
g2017_day_08.bench_function("year_2017::day_08_v1", |b| {
b.iter(|| day_08::day_08_v1(black_box(input_day_08)))
});
g2017_day_08.bench_function("year_2017::day_08_v2", |b| {
b.iter(|| day_08::day_08_v2(black_box(input_day_08)))
});
g2017_day_08.finish();
}

fn year_2017_day_09(c: &mut Criterion) {
let input_day_09 = include_str!("../inputs/year_2017/day_09_input");
assert_eq!(day_09::day_09_v1(black_box(input_day_09)), 17_537);
assert_eq!(day_09::day_09_v2(black_box(input_day_09)), 7_539);

let mut g2017_day_09 = c.benchmark_group("year_2017::day_09");
g2017_day_09.bench_function("year_2017::day_09_v1", |b| {
b.iter(|| day_09::day_09_v1(black_box(input_day_09)))
});
g2017_day_09.bench_function("year_2017::day_09_v2", |b| {
b.iter(|| day_09::day_09_v2(black_box(input_day_09)))
});
g2017_day_09.finish();
}

fn year_2017_day_10(c: &mut Criterion) {
let input_day_10 = include_str!("../inputs/year_2017/day_10_input");
assert_eq!(day_10::day_10_v1(input_day_10), "6909");
assert_eq!(
day_10::day_10_v2(input_day_10),
"9d5f4561367d379cfbf04f8c471c0095"
);

let mut g2017_day_10 = c.benchmark_group("year_2017::day_10");
g2017_day_10.bench_function("year_2017::day_10_v1", |b| {
b.iter(|| day_10::day_10_v1(black_box(input_day_10)))
});
g2017_day_10.bench_function("year_2017::day_10_v2", |b| {
b.iter(|| day_10::day_10_v2(black_box(input_day_10)))
});
g2017_day_10.finish();
}

fn year_2017_day_11(c: &mut Criterion) {
let input_day_11 = include_str!("../inputs/year_2017/day_11_input");
assert_eq!(day_11::day_11_v1(black_box(input_day_11)), 682);
assert_eq!(day_11::day_11_v2(black_box(input_day_11)), 1_406);

let mut g2017_day_11 = c.benchmark_group("year_2017::day_11");
g2017_day_11.bench_function("year_2017::day_11_v1", |b| {
b.iter(|| day_11::day_11_v1(black_box(input_day_11)))
});
g2017_day_11.bench_function("year_2017::day_11_v2", |b| {
b.iter(|| day_11::day_11_v2(black_box(input_day_11)))
});
g2017_day_11.finish();
}

fn year_2017_day_12(c: &mut Criterion) {
let input_day_12 = include_str!("../inputs/year_2017/day_12_input");
assert_eq!(day_12::day_12_v1(black_box(input_day_12)), 130);
assert_eq!(day_12::day_12_v2(black_box(input_day_12)), 189);

let mut g2017_day_12 = c.benchmark_group("year_2017::day_12");
g2017_day_12.bench_function("year_2017::day_12_v1", |b| {
b.iter(|| day_12::day_12_v1(black_box(input_day_12)))
});
g2017_day_12.bench_function("year_2017::day_12_v2", |b| {
b.iter(|| day_12::day_12_v2(black_box(input_day_12)))
});
g2017_day_12.finish();
}

criterion_group!(
benches,
year_2017_day_01,
Expand All @@ -99,6 +203,11 @@ criterion_group!(
year_2017_day_04,
year_2017_day_05,
year_2017_day_06,
year_2017_day_07
year_2017_day_07,
year_2017_day_08,
year_2017_day_09,
year_2017_day_10,
year_2017_day_11,
year_2017_day_12
);
criterion_main!(benches);
Loading

0 comments on commit ee53f47

Please sign in to comment.