diff options
author | Guillermo Ramos | 2024-12-06 15:59:32 +0100 |
---|---|---|
committer | Guillermo Ramos | 2024-12-06 16:29:18 +0100 |
commit | ff064b6f13019b15346ff320a486d70b95d80b2a (patch) | |
tree | 396868cbbd9be95f6ce0a808f8436d4a1a0f1d89 /2024_rust/src/day3.rs | |
parent | a6029017bb354381c17afaf00526442966648c3f (diff) | |
download | AoC-ff064b6f13019b15346ff320a486d70b95d80b2a.tar.gz |
Each day is now a binary
Diffstat (limited to '2024_rust/src/day3.rs')
-rw-r--r-- | 2024_rust/src/day3.rs | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/2024_rust/src/day3.rs b/2024_rust/src/day3.rs deleted file mode 100644 index cdcd62a..0000000 --- a/2024_rust/src/day3.rs +++ /dev/null @@ -1,33 +0,0 @@ -use regex::Regex; - -pub fn p1(input: &str) -> String { - let re = Regex::new(r"mul\(([0-9]{1,3}),([0-9]{1,3})\)").unwrap(); - - let mut result: u32 = 0; - for (_, [x, y]) in re.captures_iter(input).map(|cs| cs.extract()) { - result += x.parse::<u32>().unwrap() * y.parse::<u32>().unwrap(); - } - - result.to_string() -} - -pub fn p2(input: &str) -> String { - let re = Regex::new(r"do\(\)|don't\(\)|mul\(([0-9]{1,3}),([0-9]{1,3})\)").unwrap(); - - let mut doing = true; - let mut result: u32 = 0; - for cs in re.captures_iter(input) { - let mut it = cs.iter().flatten().map(|m| m.as_str()); - match it.next().unwrap() { - "do()" => doing = true, - "don't()" => doing = false, - mul if doing && mul.starts_with("mul") => { - let mut next = || it.next().unwrap().parse::<u32>().unwrap(); - result += next() * next(); - } - _ => (), - } - } - - result.to_string() -} |