Skip to content

Commit 55bb6d6

Browse files
committed
refactor(11/2025): try to solve it counting parts lengths - still fail
1 parent 595fc85 commit 55bb6d6

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/solutions/year2025/day11.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::solutions::Solution;
22
use crate::utils::graphs::all_paths::AllPaths;
33
use crate::utils::graphs::graph::Graph;
4-
use std::collections::VecDeque;
54

65
pub struct Day11;
76

@@ -21,14 +20,23 @@ impl Solution for Day11 {
2120

2221
fn part_two(&self, input: &str) -> String {
2322
let graph = self.parse(input);
23+
// todo reverse graph for directed only
24+
// if undirected it is just the same?
2425
let all_paths: AllPaths<&str> = (&graph).into();
2526

26-
let should_count_path =
27-
|path: &VecDeque<&str>| path.contains(&LABEL_DAC) && path.contains(&LABEL_FFT);
27+
// find depth of every path and then pass it as parameter
2828

29-
all_paths
30-
.count_paths(LABEL_SVR, LABEL_OUT, should_count_path)
31-
.to_string()
29+
let svr_dac = all_paths.count_paths(LABEL_SVR, LABEL_DAC);
30+
let dac_fft = all_paths.count_paths(LABEL_DAC, LABEL_FFT);
31+
let fft_out = all_paths.count_paths(LABEL_FFT, LABEL_OUT);
32+
let svr_dac_fft_out = svr_dac * dac_fft * fft_out;
33+
34+
let svr_fft = all_paths.count_paths(LABEL_SVR, LABEL_FFT);
35+
let fft_dac = all_paths.count_paths(LABEL_FFT, LABEL_DAC);
36+
let dac_out = all_paths.count_paths(LABEL_DAC, LABEL_OUT);
37+
let scr_fft_dac_out = svr_fft * fft_dac * dac_out;
38+
39+
(svr_dac_fft_out + scr_fft_dac_out).to_string()
3240
}
3341
}
3442

src/utils/graphs/all_paths.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ where
9090
visited.remove(&from);
9191
}
9292

93-
pub fn count_paths<E>(
93+
pub fn count_paths<E>(&self, start: T, end: E) -> usize
94+
where
95+
E: IsEnd<T>,
96+
{
97+
self.count_paths_with_condition(start, end, |_: &VecDeque<T>| true)
98+
}
99+
100+
pub fn count_paths_with_condition<E>(
94101
&self,
95102
start: T,
96103
end: E,
@@ -122,6 +129,8 @@ where
122129
visited.insert(from); // probably is not needed for graph
123130
path.push_back(from);
124131

132+
println!("{} {:?}", path.len(), path);
133+
125134
if end.is_end(&from) {
126135
if should_count_path(path) {
127136
count += 1;

0 commit comments

Comments
 (0)