Skip to content

Commit

Permalink
Solve Day 3 Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
destinationunknown committed Dec 4, 2024
1 parent 99a5a05 commit d9363b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/examples/03.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
38 changes: 38 additions & 0 deletions src/bin/03.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
advent_of_code::solution!(3);

use regex::Regex;

pub fn part_one(input: &str) -> Option<u32> {
let re = Regex::new(r"mul\((\d+),(\d+)\)").unwrap();
let result = re
.captures_iter(input)
.filter_map(|x| {
let first = x[1].parse::<u32>().ok()?;
let second = x[2].parse::<u32>().ok()?;
Some(first * second)
})
.sum();

Some(result)
}

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

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_part_one() {
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
assert_eq!(result, Some(161));
}

#[test]
fn test_part_two() {
let result = part_two(&advent_of_code::template::read_file("examples", DAY));
assert_eq!(result, None);
}
}

0 comments on commit d9363b9

Please sign in to comment.