generated from fspoettel/advent-of-code-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb440d4
commit 7333c6d
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!()); | ||
} | ||
} |