@@ -16,7 +16,7 @@ fn pathfind(connections: &[(&str, &str)], start: &str, end: &str) -> u64 {
1616
1717 let mut ans = 0 ;
1818
19- for _ in 0 ..connections. len ( ) {
19+ for _ in 0 ..connections. len ( ) - 1 {
2020 let mut new = HashMap :: < & str , u64 > :: default ( ) ;
2121
2222 connections. iter ( ) . for_each ( |( s, e) | {
@@ -48,12 +48,22 @@ fn calculate_p1(connections: &[(&str, &str)]) -> u64 {
4848}
4949
5050fn calculate_p2 ( connections : & [ ( & str , & str ) ] ) -> u64 {
51- ( pathfind ( connections, "svr" , "dac" )
52- * pathfind ( connections, "dac" , "fft" )
53- * pathfind ( connections, "fft" , "out" ) )
54- + ( pathfind ( connections, "svr" , "fft" )
55- * pathfind ( connections, "fft" , "dac" )
56- * pathfind ( connections, "dac" , "out" ) )
51+ // (pathfind(connections, "svr", "dac")
52+ // * pathfind(connections, "dac", "fft")
53+ // * pathfind(connections, "fft", "out"))
54+ // + (pathfind(connections, "svr", "fft")
55+ // * pathfind(connections, "fft", "dac")
56+ // * pathfind(connections, "dac", "out"))
57+
58+ let fft_to_dac = pathfind ( connections, "fft" , "dac" ) ;
59+ println ! ( "fft to dac={fft_to_dac}" ) ;
60+ if fft_to_dac != 0 {
61+ pathfind ( connections, "svr" , "fft" ) * fft_to_dac * pathfind ( connections, "dac" , "out" )
62+ } else {
63+ pathfind ( connections, "svr" , "dac" )
64+ * pathfind ( connections, "dac" , "fft" )
65+ * pathfind ( connections, "fft" , "out" )
66+ }
5767}
5868
5969pub fn run_2025_11 ( inp : & str ) -> Result < String > {
0 commit comments