Skip to content

Commit f90cbfe

Browse files
committed
Year 2025 Day 11
1 parent c16d8bf commit f90cbfe

File tree

7 files changed

+99
-4
lines changed

7 files changed

+99
-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) | 100 |
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! # Reactor
2+
use crate::util::hash::*;
3+
4+
pub struct Input<'a> {
5+
indices: FastMap<&'a str, usize>,
6+
graph: Vec<Vec<usize>>,
7+
}
8+
9+
pub fn parse(input: &str) -> Input<'_> {
10+
let nodes: Vec<Vec<_>> =
11+
input.lines().map(|line| line.split_ascii_whitespace().collect()).collect();
12+
let mut indices = FastMap::new();
13+
14+
for label in nodes.iter().flatten() {
15+
let size = indices.len();
16+
indices.entry(&label[..3]).or_insert(size);
17+
}
18+
19+
let mut graph = vec![vec![]; indices.len()];
20+
21+
for edges in nodes {
22+
let from = indices[&edges[0][..3]];
23+
graph[from].extend(edges[1..].iter().map(|label| indices[label]));
24+
}
25+
26+
Input { indices, graph }
27+
}
28+
29+
pub fn part1(input: &Input<'_>) -> u64 {
30+
paths(input, "you", "out")
31+
}
32+
33+
pub fn part2(input: &Input<'_>) -> u64 {
34+
let one = paths(input, "svr", "fft") * paths(input, "fft", "dac") * paths(input, "dac", "out");
35+
let two = paths(input, "svr", "dac") * paths(input, "dac", "fft") * paths(input, "fft", "out");
36+
one + two
37+
}
38+
39+
fn paths(input: &Input<'_>, from: &str, to: &str) -> u64 {
40+
let mut cache = vec![u64::MAX; input.indices.len()];
41+
dfs(input, &mut cache, input.indices[from], input.indices[to])
42+
}
43+
44+
fn dfs(input: &Input<'_>, cache: &mut [u64], node: usize, end: usize) -> u64 {
45+
if node == end {
46+
1
47+
} else if cache[node] == u64::MAX {
48+
let result = input.graph[node].iter().map(|&next| dfs(input, cache, next, end)).sum();
49+
cache[node] = result;
50+
result
51+
} else {
52+
cache[node]
53+
}
54+
}

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)