Skip to content

Commit 92f82f8

Browse files
committed
Year 2025 Day 11
1 parent c16d8bf commit 92f82f8

File tree

7 files changed

+90
-4
lines changed

7 files changed

+90
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Performance is reasonable even on older hardware, for example a 2011 MacBook Pro
8787
| 8 | [Playground](https://adventofcode.com/2025/day/8) | [Source](src/year2025/day08.rs) | 527 |
8888
| 9 | [Movie Theater](https://adventofcode.com/2025/day/9) | [Source](src/year2025/day09.rs) | 668 |
8989
| 10 | [Factory](https://adventofcode.com/2025/day/10) | [Source](src/year2025/day10.rs) | 117* |
90+
| 11 | [Reactor](https://adventofcode.com/2025/day/11) | [Source](src/year2025/day11.rs) | 75 |
9091

9192
## 2024
9293

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, day07, day08, day09, day10
98+
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11
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, day07, day08, day09, day10
77+
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11
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, day07, day08, day09, day10
144+
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11
145145
);

src/year2025/day11.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//! # Reactor
2+
type Input = Vec<Vec<usize>>;
3+
4+
pub fn parse(input: &str) -> Input {
5+
let mut graph = vec![vec![]; 26 * 26 * 26];
6+
7+
for line in input.lines() {
8+
let mut edges = line.split_ascii_whitespace();
9+
let from = edges.next().unwrap();
10+
graph[to_index(from)].extend(edges.map(to_index));
11+
}
12+
13+
graph
14+
}
15+
16+
pub fn part1(input: &Input) -> u64 {
17+
paths(input, "you", "out")
18+
}
19+
20+
pub fn part2(input: &Input) -> u64 {
21+
let one = paths(input, "svr", "fft") * paths(input, "fft", "dac") * paths(input, "dac", "out");
22+
let two = paths(input, "svr", "dac") * paths(input, "dac", "fft") * paths(input, "fft", "out");
23+
one + two
24+
}
25+
26+
fn paths(input: &Input, from: &str, to: &str) -> u64 {
27+
let mut cache = vec![u64::MAX; input.len()];
28+
dfs(input, &mut cache, to_index(from), to_index(to))
29+
}
30+
31+
fn dfs(input: &Input, cache: &mut [u64], node: usize, end: usize) -> u64 {
32+
if node == end {
33+
1
34+
} else if cache[node] == u64::MAX {
35+
let result = input[node].iter().map(|&next| dfs(input, cache, next, end)).sum();
36+
cache[node] = result;
37+
result
38+
} else {
39+
cache[node]
40+
}
41+
}
42+
43+
fn to_index(s: &str) -> usize {
44+
s.bytes().take(3).fold(0, |acc, b| 26 * acc + usize::from(b - b'a'))
45+
}

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, day07, day08, day09, day10
90+
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11
9191
);

tests/year2025/day11.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use aoc::year2025::day11::*;
2+
3+
const EXAMPLE_ONE: &str = "\
4+
aaa: you hhh
5+
you: bbb ccc
6+
bbb: ddd eee
7+
ccc: ddd eee fff
8+
ddd: ggg
9+
eee: out
10+
fff: out
11+
ggg: out
12+
hhh: ccc fff iii
13+
iii: out";
14+
15+
const EXAMPLE_TWO: &str = "\
16+
svr: aaa bbb
17+
aaa: fft
18+
fft: ccc
19+
bbb: tty
20+
tty: ccc
21+
ccc: ddd eee
22+
ddd: hub
23+
hub: fff
24+
eee: dac
25+
dac: fff
26+
fff: ggg hhh
27+
ggg: out
28+
hhh: out";
29+
30+
#[test]
31+
fn part1_test() {
32+
let input = parse(EXAMPLE_ONE);
33+
assert_eq!(part1(&input), 5);
34+
}
35+
36+
#[test]
37+
fn part2_test() {
38+
let input = parse(EXAMPLE_TWO);
39+
assert_eq!(part2(&input), 2);
40+
}

0 commit comments

Comments
 (0)