D1P2 - Why did I do that?

This commit is contained in:
Logan G 2024-12-01 00:11:56 -07:00
parent aa7351c5a6
commit ba1333d14e
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -41,25 +41,10 @@ fn main() {
left.sort(); left.sort();
right.sort(); right.sort();
let mut left_dup = HashMap::new();
let mut right_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; 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() { while i < right.len() {
let mut k: usize = i; let mut k: usize = i;
while k < right.len() && right[i] == right[k] { while k < right.len() && right[i] == right[k] {
@ -71,15 +56,13 @@ fn main() {
i = k; i = k;
} }
//println!("{}", right_dup[&3]);
let mut accum: i32 = 0; let mut accum: i32 = 0;
for (left, num) in &left_dup { for num in left {
let shit = match right_dup.get(left) { let shit = match right_dup.get(&num) {
Some(val) => *val, Some(val) => *val,
None => 0, None => 0,
}; };
accum += (*left * (*num as i32)) * (shit as i32); accum += num * (shit as i32);
} }
println!("Answer: {}", accum); println!("Answer: {}", accum);