Skip to content

Commit

Permalink
Year 2017: Day 06+07
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleaves committed Mar 26, 2024
1 parent 248fd7c commit f5912f4
Show file tree
Hide file tree
Showing 10 changed files with 1,782 additions and 33 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)

## [2017.7.1]
### Added
- Solved [exercice for 2017, day 06](src/year_2017/06.rs).
- Solved [exercice for 2017, day 07](src/year_2017/07.rs).

## [2017.5.1]
### Added
- Solved [exercice for 2017, day 01](src/year_2017/01.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.5.1"
version = "2017.7.1"
edition = "2021"
authors = ["Arnaud 'red' Rouyer"]
readme = "README.md"
Expand Down
10 changes: 10 additions & 0 deletions NOTES_2017.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ Knowing how to use iterators properly is often the key to winning.
## Day 05: A Maze of Twisty Trampolines, All Alike

I was expecting more difficulty here.

## Day 06: Memory Reallocation

No idea why, but I cannot get this one to go faster at all.

## Day 07: Recursive Circus

Little-known fact about me: I hate traversing trees.

That said, you can always find ways to avoid doing it :D
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 05](NOTES_2017.md)
- [2017, up to day 07](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
75 changes: 44 additions & 31 deletions benches/year_2017.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,102 @@ use advent_rs::year_2017::day_02;
use advent_rs::year_2017::day_03;
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 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_year_2017_day_01 = include_str!("../inputs/year_2017/day_01_input");
let input_day_01 = include_str!("../inputs/year_2017/day_01_input");
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_year_2017_day_01))))
b.iter(|| assert_eq!(1_069, 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_year_2017_day_01))))
b.iter(|| assert_eq!(1_268, 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_year_2017_day_02 = include_str!("../inputs/year_2017/day_02_input");
let input_day_02 = include_str!("../inputs/year_2017/day_02_input");
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_year_2017_day_02))))
b.iter(|| assert_eq!(53_978, 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_year_2017_day_02))))
b.iter(|| assert_eq!(314, 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_year_2017_day_03 = include_str!("../inputs/year_2017/day_03_input");
let input_day_03 = include_str!("../inputs/year_2017/day_03_input");
g2017_day_03.bench_function("year_2017::day_03_v1", |b| {
b.iter(|| assert_eq!(552, day_03::day_03_v1(black_box(input_year_2017_day_03))))
b.iter(|| assert_eq!(552, 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_year_2017_day_03))
)
})
b.iter(|| assert_eq!(330_785, 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_year_2017_day_04 = include_str!("../inputs/year_2017/day_04_input");
let input_day_04 = include_str!("../inputs/year_2017/day_04_input");
g2017_day_04.bench_function("year_2017::day_04_v1", |b| {
b.iter(|| assert_eq!(466, day_04::day_04_v1(black_box(input_year_2017_day_04))))
b.iter(|| assert_eq!(466, 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_year_2017_day_04))))
b.iter(|| assert_eq!(251, 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_year_2017_day_05 = include_str!("../inputs/year_2017/day_05_input");
let input_day_05 = include_str!("../inputs/year_2017/day_05_input");
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_year_2017_day_05))
)
})
b.iter(|| assert_eq!(373_160, 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_year_2017_day_05))
)
})
b.iter(|| assert_eq!(26_395_586, 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");
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))))
});
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))))
});
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");
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))))
});
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))))
});
g2017_day_07.finish();
}

criterion_group!(
benches,
year_2017_day_01,
year_2017_day_02,
year_2017_day_03,
year_2017_day_04,
year_2017_day_05
year_2017_day_05,
year_2017_day_06,
year_2017_day_07
);
criterion_main!(benches);
1 change: 1 addition & 0 deletions inputs/year_2017/day_06_input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14 0 15 12 11 11 3 5 1 6 8 4 9 1 8 4
Loading

0 comments on commit f5912f4

Please sign in to comment.