Skip to content

Commit ce17385

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

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) | 186 |
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+
use crate::util::hash::*;
3+
4+
type Input<'a> = FastMap<&'a str, Vec<&'a str>>;
5+
6+
pub fn parse(input: &str) -> Input<'_> {
7+
let mut graph = FastMap::new();
8+
9+
for line in input.lines() {
10+
let mut tokens: Vec<_> = line.split_ascii_whitespace().collect();
11+
let first = tokens.remove(0);
12+
let key = &first[0..first.len() - 1];
13+
graph.insert(key, tokens);
14+
}
15+
16+
graph
17+
}
18+
19+
pub fn part1(input: &Input<'_>) -> u64 {
20+
dfs(input, &mut FastMap::new(), "you", "out")
21+
}
22+
23+
pub fn part2(input: &Input<'_>) -> u64 {
24+
let first = dfs(input, &mut FastMap::new(), "svr", "fft")
25+
* dfs(input, &mut FastMap::new(), "fft", "dac")
26+
* dfs(input, &mut FastMap::new(), "dac", "out");
27+
let second = dfs(input, &mut FastMap::new(), "svr", "dac")
28+
* dfs(input, &mut FastMap::new(), "dac", "fft")
29+
* dfs(input, &mut FastMap::new(), "fft", "out");
30+
first + second
31+
}
32+
33+
fn dfs<'a>(graph: &Input<'a>, cache: &mut FastMap<&'a str, u64>, node: &'a str, end: &str) -> u64 {
34+
if node == end {
35+
1
36+
} else if node == "out" {
37+
0
38+
} else if let Some(&previous) = cache.get(&node) {
39+
previous
40+
} else {
41+
let result = graph[&node].iter().map(|&next| dfs(graph, cache, next, end)).sum();
42+
cache.insert(node, result);
43+
result
44+
}
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)