From ba1333d14e734ccd879ef84c9ad097824cb64c8d Mon Sep 17 00:00:00 2001 From: Logan G Date: Sun, 1 Dec 2024 00:11:56 -0700 Subject: [PATCH] D1P2 - Why did I do that? --- day1/p2.rs | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/day1/p2.rs b/day1/p2.rs index 2c45236..9cc685c 100644 --- a/day1/p2.rs +++ b/day1/p2.rs @@ -41,25 +41,10 @@ fn main() { left.sort(); right.sort(); - let mut left_dup = HashMap::new(); let mut right_dup = HashMap::new(); - // This is kinda ass but I don't care :) + // This is still kinda ass but I don't care :) let mut i: usize = 0; - while i < left.len() { - let mut k: usize = i; - while k < left.len() && left[i] == left[k] { - k+=1; - } - - left_dup.insert(left[i],k-i); - - i = k; - } - - //println!("{}", left_dup[&3]); - - i = 0; while i < right.len() { let mut k: usize = i; while k < right.len() && right[i] == right[k] { @@ -71,15 +56,13 @@ fn main() { i = k; } - //println!("{}", right_dup[&3]); - let mut accum: i32 = 0; - for (left, num) in &left_dup { - let shit = match right_dup.get(left) { + for num in left { + let shit = match right_dup.get(&num) { Some(val) => *val, None => 0, }; - accum += (*left * (*num as i32)) * (shit as i32); + accum += num * (shit as i32); } println!("Answer: {}", accum);