Skip to content

Commit

Permalink
feat: complete day 3 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzHayden committed Dec 3, 2024
1 parent 71f09a4 commit 4be2584
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/bin/03.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
use regex::Regex;

advent_of_code::solution!(3);

pub fn part_one(input: &str) -> Option<u32> {
None
// Define variables
let mut product: u32;
let mut result: u32 = 0;

// Extract each mul instruction using multiple regex capturing groups
let re = Regex::new(r"(mul\((\d{1,3}),(\d{1,3})\))").unwrap();

// Calculate the product of each mul instruction
for cap in re.captures_iter(input) {
let left_instruction: u32 = cap[2].parse::<u32>().unwrap();
let right_instruction: u32 = cap[3].parse::<u32>().unwrap();
product = left_instruction * right_instruction;
result += product;
}

// Return the total sum of products
Some(result)
}

pub fn part_two(input: &str) -> Option<u32> {
pub fn part_two(_input: &str) -> Option<u32> {
None
}

Expand All @@ -21,6 +39,6 @@ mod tests {
#[test]
fn test_part_two() {
let result = part_two(&advent_of_code::template::read_file("examples", DAY));
assert_eq!(result, None);
assert_eq!(result, Some(48));
}
}

0 comments on commit 4be2584

Please sign in to comment.