Skip to content

Commit

Permalink
part 1 done
Browse files Browse the repository at this point in the history
  • Loading branch information
pawarherschel committed Dec 3, 2024
1 parent bb440d4 commit 7333c6d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
51 changes: 50 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ test_lib = []
chrono = { version = "0.4.38", optional = true }
dhat = { version = "0.3.3", optional = true }
pico-args = "0.5.0"
regex = "1.11.1"
tinyjson = "2.5.1"
winnow = "0.6.20"

# Solution dependencies
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))
41 changes: 41 additions & 0 deletions src/bin/03.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use regex::Regex;

advent_of_code::solution!(3);

#[must_use]
pub fn part_one(input: &str) -> Option<u32> {
let re = Regex::new(r"mul\((?<n1>\d{1,3}),(?<n2>\d{1,3})\)").unwrap();
Some(
re.captures_iter(input)
.map(|caps| {
let (_full, [n1, n2]) = caps.extract();
(n1, n2)
})
.map(|(n1, n2)| (n1.parse::<u32>().unwrap(), n2.parse::<u32>().unwrap()))
.map(|(n1, n2)| n1 * n2)
.sum(),
)
}

#[must_use]
pub fn part_two(input: &str) -> Option<u32> {
// let x = parse_3(input);
todo!()
}

#[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, todo!());
}
}

0 comments on commit 7333c6d

Please sign in to comment.