tangled
alpha
login
or
join now
cherry.computer
/
aoc25
My submissions for Advent of Code 2025
adventofcode.com/2025
rust
aoc
0
fork
atom
overview
issues
pulls
pipelines
add solution for day 11 part 2
cherry.computer
1 month ago
6523234a
e30c341f
verified
This commit was signed with the committer's
known signature
.
cherry.computer
SSH Key Fingerprint:
SHA256:SIA77Ll0IpMb8Xd3RtaGT+PBIGIePhJJg5W2r6Td7cc=
+54
3 changed files
expand all
collapse all
unified
split
11
part2
Cargo.toml
src
main.rs
Cargo.lock
+4
11/part2/Cargo.toml
···
1
1
+
[package]
2
2
+
name = "aoc25-11-2"
3
3
+
version = "1.0.0"
4
4
+
edition = "2024"
+46
11/part2/src/main.rs
···
1
1
+
use std::{collections::HashMap, fs::read_to_string};
2
2
+
3
3
+
fn traverse_map<'a>(
4
4
+
device_map: &HashMap<&'a str, Vec<&'a str>>,
5
5
+
seen_paths: &mut HashMap<&'a str, u64>,
6
6
+
device: &'a str,
7
7
+
target: &'a str,
8
8
+
) -> u64 {
9
9
+
match seen_paths.get(device) {
10
10
+
Some(&known_path_count) => known_path_count,
11
11
+
None => {
12
12
+
let path_count = match &device_map.get(device) {
13
13
+
Some(outputs) => outputs
14
14
+
.iter()
15
15
+
.map(|&output| {
16
16
+
if output == target {
17
17
+
1
18
18
+
} else {
19
19
+
traverse_map(device_map, seen_paths, output, target)
20
20
+
}
21
21
+
})
22
22
+
.sum(),
23
23
+
None => 0,
24
24
+
};
25
25
+
seen_paths.insert(device, path_count);
26
26
+
path_count
27
27
+
}
28
28
+
}
29
29
+
}
30
30
+
31
31
+
fn main() {
32
32
+
let input = read_to_string("../input.txt").expect("failed to open input file");
33
33
+
let device_map: HashMap<_, Vec<_>> = input
34
34
+
.lines()
35
35
+
.map(|line| {
36
36
+
let (device, outputs) = line.split_once(": ").expect("failed to parse line");
37
37
+
(device, outputs.split_whitespace().collect())
38
38
+
})
39
39
+
.collect();
40
40
+
41
41
+
let total_paths: u64 = [("svr", "fft"), ("fft", "dac"), ("dac", "out")]
42
42
+
.into_iter()
43
43
+
.map(|(from, to)| traverse_map(&device_map, &mut HashMap::new(), from, to))
44
44
+
.product();
45
45
+
println!("There are {total_paths} faulty paths from 'svr' to 'out'!");
46
46
+
}
+4
Cargo.lock
···
107
107
version = "1.0.0"
108
108
109
109
[[package]]
110
110
+
name = "aoc25-11-2"
111
111
+
version = "1.0.0"
112
112
+
113
113
+
[[package]]
110
114
name = "autocfg"
111
115
version = "1.5.0"
112
116
source = "registry+https://github.com/rust-lang/crates.io-index"