Skip to content

Commit

Permalink
feat: complete day 1 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzHayden committed Dec 1, 2024
1 parent f7bbe67 commit aa9ae32
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/bin/01.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use regex::Regex;
use std::cmp::Ordering;

advent_of_code::solution!(1);

Expand All @@ -20,12 +21,10 @@ pub fn part_one(input: &str) -> Option<u32> {

// 3. Iterate through the lists and calculate the difference between the two corresponding elements
for (left, right) in left_locations.iter().zip(right_locations.iter()) {
if left > right {
total_diff += left - right;
} else if right > left {
total_diff += right - left;
} else {
total_diff += 0;
match left.cmp(right) {
Ordering::Greater => total_diff += left - right,
Ordering::Less => total_diff += right - left,
_ => total_diff += 0,
}
}

Expand All @@ -51,8 +50,6 @@ pub fn part_two(input: &str) -> Option<u32> {

// 3. Iterate through the lists and calculate the similarity scores
for left in left_locations.iter() {
println!("left: {}", *left);
println!("right_locations: {}", right_locations.iter().filter(|x| *x == left).count());
similarity_score += left * right_locations.iter().filter(|x| *x == left).count() as u32;
}

Expand Down

0 comments on commit aa9ae32

Please sign in to comment.