Skip to content

Commit

Permalink
refactor(2023): use a simple sum for day 3 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Dec 3, 2023
1 parent 75a83e3 commit 33d4a52
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions rust/2023/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | - | | |
6 changes: 3 additions & 3 deletions rust/2023/src/day_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -120,7 +120,7 @@ pub fn solve_part_01(input: &Input) -> u32 {
}
}

part_numbers.iter().sum()
part_numbers
}

/* Part Two
Expand Down

0 comments on commit 33d4a52

Please sign in to comment.