diff --git a/rust/2023/README.md b/rust/2023/README.md index b8f871b..cc06de4 100644 --- a/rust/2023/README.md +++ b/rust/2023/README.md @@ -28,12 +28,12 @@ With the help of [cargo-aoc](https://github.com/gobanos/cargo-aoc) I get automat | --- | --------: | ------: | ------------- | --------: | | 1 | 43.18 ns | 1.19 ms | - | 441.01 ns | | 2 | 764.68 ns | 1.75 µs | - | 47.81 µs | -| 3 | 172.23 µs | 7.72 ms | - | 86.83 µs | +| 3 | 159.61 µs | 7.72 ms | `-8.44%` | 86.83 µs | \* compared to first solution ### Previous solutions -| Day | #1 | #2 | Improvement | Link | -| --: | --: | --: | ----------: | ---- | -| 1 | - | - | | | +| Day | #1 | #2 | Improvement | Link | +| --: | --------: | --: | ----------: | ---- | +| 3 | 172.23 µs | - | | | diff --git a/rust/2023/src/day_03.rs b/rust/2023/src/day_03.rs index 2b3f03b..1187246 100644 --- a/rust/2023/src/day_03.rs +++ b/rust/2023/src/day_03.rs @@ -104,14 +104,14 @@ pub fn solve_part_01(input: &Input) -> u32 { let Input { symbols, numbers, .. } = input; - let mut part_numbers = vec![]; + let mut part_numbers = 0; for (number, points) in numbers { 'points: for (x, y) in points { for check_point in DIAGONALS.iter().map(|(dx, dy)| (dx + x, dy + y)) { // If the point is in the list of symbols, it's a "part number" if symbols.contains(&check_point) { - part_numbers.push(*number); + part_numbers += number; // We don't need to check any more points for this number break 'points; @@ -120,7 +120,7 @@ pub fn solve_part_01(input: &Input) -> u32 { } } - part_numbers.iter().sum() + part_numbers } /* Part Two