tangled
alpha
login
or
join now
bwc9876.dev
/
advent
0
fork
atom
Advent of Code solutions
0
fork
atom
overview
issues
pulls
pipelines
Day 11: Some cleanup
bwc9876.dev
3 months ago
9ae06fd4
95726946
verified
This commit was signed with the committer's
known signature
.
bwc9876.dev
SSH Key Fingerprint:
SHA256:DanMEP/RNlSC7pAVbnXO6wzQV00rqyKj053tz4uH5gQ=
+13
-16
1 changed file
expand all
collapse all
unified
split
years
2025
src
day_11.rs
+13
-16
years/2025/src/day_11.rs
···
5
5
pub struct Day11;
6
6
7
7
type Graph = HashMap<String, Vec<String>>;
8
8
-
type Seen<'a> = HashMap<(&'a String, bool, bool), usize>;
8
8
+
type Seen<'a> = HashMap<&'a String, usize>;
9
9
+
type SeenConstrained<'a> = HashMap<(&'a String, bool, bool), usize>;
9
10
10
10
-
fn all_paths_to_out<'a>(
11
11
-
node: &'a String,
12
12
-
graph: &'a Graph,
13
13
-
seen: &mut HashMap<&'a String, usize>,
14
14
-
) -> usize {
11
11
+
fn all_paths_to_out<'a>(node: &'a String, graph: &'a Graph, seen: &mut Seen<'a>) -> usize {
15
12
if let Some(memo) = seen.get(&node) {
16
13
*memo
17
14
} else if let Some(nexts) = graph.get(node) {
···
30
27
}
31
28
}
32
29
33
33
-
fn all_paths_to_out_with_constraints<'a>(
30
30
+
fn all_paths_to_out_constrained<'a>(
34
31
node: &'a String,
35
32
saw_dac: bool,
36
33
saw_fft: bool,
37
34
graph: &'a Graph,
38
38
-
seen: &mut Seen<'a>,
35
35
+
seen: &mut SeenConstrained<'a>,
39
36
) -> usize {
40
37
if let Some(memo) = seen.get(&(node, saw_dac, saw_fft)) {
41
38
*memo
42
39
} else if let Some(nexts) = graph.get(node) {
43
40
let mut amnt = 0;
44
41
for next in nexts.iter() {
45
45
-
if next == "out" && saw_fft && saw_dac {
46
46
-
amnt += 1;
42
42
+
if next == "out" {
43
43
+
if saw_dac && saw_fft {
44
44
+
amnt += 1;
45
45
+
}
47
46
} else {
48
48
-
let is_dac = next == "dac";
49
49
-
let is_fft = next == "fft";
50
50
-
amnt += all_paths_to_out_with_constraints(
47
47
+
amnt += all_paths_to_out_constrained(
51
48
next,
52
52
-
saw_dac || is_dac,
53
53
-
saw_fft || is_fft,
49
49
+
saw_dac || next == "dac",
50
50
+
saw_fft || next == "fft",
54
51
graph,
55
52
seen,
56
53
);
···
76
73
fn part_2(input: Self::Input) -> Option<String> {
77
74
let mut seen = HashMap::with_capacity(input.len());
78
75
let start = "svr".to_string();
79
79
-
let ans = all_paths_to_out_with_constraints(&start, false, false, &input, &mut seen);
76
76
+
let ans = all_paths_to_out_constrained(&start, false, false, &input, &mut seen);
80
77
Some(ans.to_string())
81
78
}
82
79