This commit is contained in:
Benjamyn Love 2024-12-02 17:32:08 +11:00
parent 6aa3307d38
commit 0992350e32

View File

@ -42,18 +42,21 @@ impl LocationList {
println!("{}", total);
}
// fn check_dupes(&mut self) {
// for (outer_pos, entry_outer) in self.left.iter().enumerate() {
// for (inner_pos, entry_inner) in self.right.iter().enumerate() {
// if entry_inner == entry_outer {
// println!(
// "Outer: {}, Inner: {}, O_Pos: {}, I_POS: {}",
// entry_outer, entry_inner, outer_pos, inner_pos
// )
// }
// }
// }
// }
fn solve2(&mut self) {
let mut total = 0;
for (_, entry_outer) in self.left.iter().enumerate() {
let mut inner_total = 0;
for (_, entry_inner) in self.right.iter().enumerate() {
if entry_inner == entry_outer {
inner_total += 1;
}
}
if inner_total != 0 {
total += entry_outer * inner_total
};
}
println!("{}", total);
}
}
impl fmt::Debug for LocationList {
@ -86,4 +89,5 @@ fn main() {
location_list.parse_data(data);
location_list.solve();
location_list.solve2();
}