11use crate :: solutions:: Solution ;
22use crate :: utils:: graphs:: all_paths:: AllPaths ;
33use crate :: utils:: graphs:: graph:: Graph ;
4- use std:: collections:: VecDeque ;
54
65pub 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
0 commit comments