From 0992350e3267d732a2121925366634eeb70fc193 Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Mon, 2 Dec 2024 17:32:08 +1100 Subject: [PATCH] Cleanup --- aoc-01/src/main.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/aoc-01/src/main.rs b/aoc-01/src/main.rs index fc32e04..83d6e8f 100644 --- a/aoc-01/src/main.rs +++ b/aoc-01/src/main.rs @@ -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(); }