Skip to content

Commit 5a83c3e

Browse files
committed
Remove calculation from parse method
1 parent 37c8065 commit 5a83c3e

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
7777

7878
| Day | Problem | Solution | Benchmark (μs) |
7979
| --- | --- | --- | --: |
80-
| 1 | [Secret Entrance](https://adventofcode.com/2025/day/1) | [Source](src/year2025/day01.rs) | 25 |
80+
| 1 | [Secret Entrance](https://adventofcode.com/2025/day/1) | [Source](src/year2025/day01.rs) | 24 |
8181
| 2 | [Gift Shop](https://adventofcode.com/2025/day/2) | [Source](src/year2025/day02.rs) | 1 |
82-
| 3 | [Lobby](https://adventofcode.com/2025/day/3) | [Source](src/year2025/day03.rs) | 18 |
83-
| 4 | [Printing Department](https://adventofcode.com/2025/day/4) | [Source](src/year2025/day04.rs) | 244 |
82+
| 3 | [Lobby](https://adventofcode.com/2025/day/3) | [Source](src/year2025/day03.rs) | 21 |
83+
| 4 | [Printing Department](https://adventofcode.com/2025/day/4) | [Source](src/year2025/day04.rs) | 177 |
8484
| 5 | [Cafeteria](https://adventofcode.com/2025/day/5) | [Source](src/year2025/day05.rs) | 20 |
8585

8686
## 2024

src/year2025/day02.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ const FIRST: [Range; 5] = [[2, 1], [4, 2], [6, 3], [8, 4], [10, 5]];
99
const SECOND: [Range; 6] = [[3, 1], [5, 1], [6, 2], [7, 1], [9, 3], [10, 2]];
1010
const THIRD: [Range; 2] = [[6, 1], [10, 1]];
1111

12-
pub fn parse(input: &str) -> Pair {
13-
let ranges: Vec<_> = input.iter_unsigned::<u64>().chunk::<2>().collect();
14-
let part_one = sum(&FIRST, &ranges);
15-
let part_two = part_one + sum(&SECOND, &ranges) - sum(&THIRD, &ranges);
16-
[part_one, part_two]
12+
pub fn parse(input: &str) -> Vec<Pair> {
13+
input.iter_unsigned::<u64>().chunk::<2>().collect()
1714
}
1815

19-
pub fn part1(input: &Pair) -> u64 {
20-
input[0]
16+
pub fn part1(input: &[Pair]) -> u64 {
17+
sum(&FIRST, input)
2118
}
2219

23-
pub fn part2(input: &Pair) -> u64 {
24-
input[1]
20+
pub fn part2(input: &[Pair]) -> u64 {
21+
sum(&FIRST, input) + sum(&SECOND, input) - sum(&THIRD, input)
2522
}
2623

27-
fn sum(ranges: &[Range], ids: &[Pair]) -> u64 {
24+
fn sum(ranges: &[Range], input: &[Pair]) -> u64 {
2825
let mut result = 0;
2926

3027
for &[digits, size] in ranges {
@@ -35,7 +32,7 @@ fn sum(ranges: &[Range], ids: &[Pair]) -> u64 {
3532
let start = step * (size_power / 10);
3633
let end = step * (size_power - 1);
3734

38-
for &[from, to] in ids {
35+
for &[from, to] in input {
3936
let lower = from.next_multiple_of(step).max(start);
4037
let upper = to.min(end);
4138

src/year2025/day04.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::util::grid::*;
33
use crate::util::point::*;
44

5-
type Input = (usize, usize);
5+
type Input = (Vec<Point>, Grid<u8>);
66

77
pub fn parse(input: &str) -> Input {
88
let grid = Grid::parse(input);
@@ -29,11 +29,20 @@ pub fn parse(input: &str) -> Input {
2929
}
3030
}
3131

32-
let part_one = todo.len();
33-
let mut part_two = 0;
32+
(todo, padded)
33+
}
34+
35+
pub fn part1(input: &Input) -> usize {
36+
let (todo, _) = input;
37+
todo.len()
38+
}
39+
40+
pub fn part2(input: &Input) -> usize {
41+
let (mut todo, mut padded) = input.clone();
42+
let mut removed = 0;
3443

3544
while let Some(point) = todo.pop() {
36-
part_two += 1;
45+
removed += 1;
3746

3847
for next in DIAGONAL.map(|d| point + d) {
3948
if padded[next] == 4 {
@@ -43,13 +52,5 @@ pub fn parse(input: &str) -> Input {
4352
}
4453
}
4554

46-
(part_one, part_two)
47-
}
48-
49-
pub fn part1(input: &Input) -> usize {
50-
input.0
51-
}
52-
53-
pub fn part2(input: &Input) -> usize {
54-
input.1
55+
removed
5556
}

src/year2025/day05.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn part1(input: &Input) -> usize {
3434
merged.iter().map(|range| position(range.end) - position(range.start)).sum()
3535
}
3636

37-
pub fn part2(input: &Input) -> usize {
37+
pub fn part2(input: &Input) -> u64 {
3838
let (merged, _) = input;
39-
merged.iter().cloned().flatten().count()
39+
merged.iter().map(|range| range.end - range.start).sum()
4040
}

0 commit comments

Comments
 (0)