diff --git a/2025/08.rs b/2025/08.rs index 5a4b390..9b615f3 100644 --- a/2025/08.rs +++ b/2025/08.rs @@ -35,7 +35,8 @@ fn main() { // println!("Distances\n{:#?}", distances); - for _ in 0..1000 { + let mut last_connection = None; + while box_circuits.len() < boxes.len() || circuits.len() > 1 { let (first, second, distance) = distances.pop().unwrap(); println!("Connecting:\n\t{:?} <=> {:?}", first, second); @@ -53,25 +54,36 @@ fn main() { first_boxes.push(b); box_circuits.insert(b, fc); } + + last_connection = Some((first, second)); }, (Some(fc), None) => { circuits.get_mut(fc).unwrap().push(*second); box_circuits.insert(*second, fc); + + last_connection = Some((first, second)); }, (None, Some(sc)) => { circuits.get_mut(sc).unwrap().push(*first); box_circuits.insert(*first, sc); + + last_connection = Some((first, second)); }, (None, None) => { let circuit = circuits.insert(vec![*first, *second]); box_circuits.insert(*first, circuit); box_circuits.insert(*second, circuit); - println!("\tCreated Circuit: {:?}", circuit); + // println!("\tCreated Circuit: {:?}", circuit); + last_connection = Some((first, second)); } }; } + let last_connection = last_connection.unwrap(); + println!("Last Connection: {:?}", last_connection); + println!("Last Connection Distance: {:?}", last_connection.0.0 * last_connection.1.0); + let mut circuit_list: Vec<_> = circuits.iter().map(|(k, v)| (k, v.len())).collect(); circuit_list.sort_by_key(|(_, v)| core::cmp::Reverse(*v));