Skip to content

Commit 4952cbe

Browse files
committed
Year 2025 Day 7
1 parent a63764e commit 4952cbe

File tree

7 files changed

+82
-4
lines changed

7 files changed

+82
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
8383
| 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
| 6 | [Trash Compactor](https://adventofcode.com/2025/day/6) | [Source](src/year2025/day06.rs) | 20 |
86+
| 7 | [Laboratories](https://adventofcode.com/2025/day/7) | [Source](src/year2025/day07.rs) | 15 |
8687

8788
## 2024
8889

benches/benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ benchmark!(year2024
9595
);
9696

9797
benchmark!(year2025
98-
day01, day02, day03, day04, day05, day06
98+
day01, day02, day03, day04, day05, day06, day07
9999
);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ library!(year2024 "Locate the Chief Historian in time for the big Christmas slei
7474
);
7575

7676
library!(year2025 "Finish the North Pole decorations in time for Christmas."
77-
day01, day02, day03, day04, day05, day06
77+
day01, day02, day03, day04, day05, day06, day07
7878
);

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ run!(year2024
141141
);
142142

143143
run!(year2025
144-
day01, day02, day03, day04, day05, day06
144+
day01, day02, day03, day04, day05, day06, day07
145145
);

src/year2025/day07.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//! # Laboratories
2+
type Input = (u64, u64);
3+
4+
pub fn parse(input: &str) -> Input {
5+
let lines: Vec<_> = input.lines().map(str::as_bytes).collect();
6+
let width = lines[0].len();
7+
let start = lines[0].iter().position(|&b| b == b'S').unwrap();
8+
9+
let mut splits = 0;
10+
let mut current = vec![0; width];
11+
let mut next = vec![0; width];
12+
13+
current[start] = 1;
14+
15+
for &row in &lines[1..] {
16+
for (x, &count) in current.iter().enumerate() {
17+
if count > 0 {
18+
if row[x] == b'^' {
19+
splits += 1;
20+
21+
if x > 0 {
22+
next[x - 1] += count;
23+
}
24+
if x + 1 < width {
25+
next[x + 1] += count;
26+
}
27+
} else {
28+
next[x] += count;
29+
}
30+
}
31+
}
32+
33+
(current, next) = (next, current);
34+
next.fill(0);
35+
}
36+
37+
(splits, current.iter().sum())
38+
}
39+
40+
pub fn part1(input: &Input) -> u64 {
41+
input.0
42+
}
43+
44+
pub fn part2(input: &Input) -> u64 {
45+
input.1
46+
}

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ test!(year2024
8787
);
8888

8989
test!(year2025
90-
day01, day02, day03, day04, day05, day06
90+
day01, day02, day03, day04, day05, day06, day07
9191
);

tests/year2025/day07.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use aoc::year2025::day07::*;
2+
3+
const EXAMPLE: &str = "\
4+
.......S.......
5+
...............
6+
.......^.......
7+
...............
8+
......^.^......
9+
...............
10+
.....^.^.^.....
11+
...............
12+
....^.^...^....
13+
...............
14+
...^.^...^.^...
15+
...............
16+
..^...^.....^..
17+
...............
18+
.^.^.^.^.^...^.
19+
...............";
20+
21+
#[test]
22+
fn part1_test() {
23+
let input = parse(EXAMPLE);
24+
assert_eq!(part1(&input), 21);
25+
}
26+
27+
#[test]
28+
fn part2_test() {
29+
let input = parse(EXAMPLE);
30+
assert_eq!(part2(&input), 40);
31+
}

0 commit comments

Comments
 (0)