Skip to content

Commit

Permalink
Year 2015: Day 07
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleaves committed Feb 26, 2024
1 parent 9342344 commit cf6737a
Show file tree
Hide file tree
Showing 10 changed files with 507 additions and 3 deletions.
15 changes: 15 additions & 0 deletions 2015.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,18 @@ year_2015::day_06/year_2015::day_06_v2
```

I started doing a copy of my original "naive" algorithm, and as it was too slow, I decided to learn [how to pass closures in Rust](https://doc.rust-lang.org/book/ch13-01-closures.html).

## Day 07: Some Assembly Required

```
test year_2015::day_07::tests::works_with_samples_v1 ... ok
test year_2015::day_07::tests::works_with_samples_v2 ... ok
test year_2015_day_07 ... ok
year_2015::day_07/year_2015::day_07_v1
time: [63.406 µs 63.509 µs 63.606 µs]
year_2015::day_07/year_2015::day_07_v2
time: [129.92 µs 130.54 µs 131.09 µs]
```

This one was already complicated in Ruby, but it gets even worse when you have to deal with [Rust's lifetimes](https://doc.rust-lang.org/rust-by-example/scope/lifetime.html). The concept in itself is kinda okay to understand, but the way it has to be used sometimes makes no sense. I guess I'll get used to it with time. A [nice crate](https://docs.rs/advent-of-code/2022.0.66/src/advent_of_code/year2015/day07.rs.html) helped me see through it a bit more clearly.
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)

## [2015.7.1]
### Added
- Solved [exercice for 2015, day 7](src/year_2015/day_07.rs).


## [2015.6.1]
### Added
- Solved [exercice for 2015, day 6](src/year_2015/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 = "2015.6.1"
version = "2015.7.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
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 discovering Rust (like I am).

Notes for solving:
* [2015, up to day 05](year_2015.md)
* [2015, up to day 07](year_2015.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
13 changes: 13 additions & 0 deletions benches/advent-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use advent_rs::year_2015::day_03;
use advent_rs::year_2015::day_04;
use advent_rs::year_2015::day_05;
use advent_rs::year_2015::day_06;
use advent_rs::year_2015::day_07;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::time::Duration;

Expand Down Expand Up @@ -84,6 +85,18 @@ pub fn year_2015_benchmark(c: &mut Criterion) {
b.iter(|| day_06::day_06_v2(black_box(input_year_2015_day_06)))
});
g2015_06.finish();

let mut g2015_07 = c.benchmark_group("year_2015::day_07");
g2015_07.warm_up_time(warm_up_time);
g2015_07.measurement_time(measurement_time);
let input_year_2015_day_07 = include_str!("../inputs/year_2015_day_07_input");
g2015_07.bench_function("year_2015::day_07_v1", |b| {
b.iter(|| day_07::day_07_v1(black_box(input_year_2015_day_07)))
});
g2015_07.bench_function("year_2015::day_07_v2", |b| {
b.iter(|| day_07::day_07_v2(black_box(input_year_2015_day_07)))
});
g2015_07.finish();
}

criterion_group!(benches, year_2015_benchmark);
Expand Down
Loading

0 comments on commit cf6737a

Please sign in to comment.