Skip to content

Commit 4ea42d1

Browse files
committed
Add day3 parser
1 parent 1f39a91 commit 4ea42d1

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

Cargo.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ edition = "2021"
66
[dependencies]
77
aoc-runner = "0.3.0"
88
aoc-runner-derive = "0.3.0"
9+
regex = "1.11.1"

src/day3.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use regex::Regex;
2+
3+
use aoc_runner_derive::{aoc, aoc_generator};
4+
5+
#[aoc_generator(day3)]
6+
pub fn input_generator(input: &str) -> Vec<String> {
7+
let re = Regex::new(r"(mul\(\d+,\d+\))").unwrap();
8+
let matches: Vec<_> = re.find_iter(input).map(|m| m.as_str()).collect();
9+
matches.iter().map(|&s| s.to_string()).collect()
10+
}
11+
12+
#[aoc(day3, part1)]
13+
pub fn part1(input: &[String]) -> usize {
14+
dbg!(input);
15+
0
16+
}
17+
18+
#[cfg(test)]
19+
mod tests {
20+
use super::*;
21+
22+
const INPUT: &str = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))";
23+
24+
#[test]
25+
fn test_part1() {
26+
assert_eq!(2, part1(&input_generator(INPUT)))
27+
}
28+
29+
// #[test]
30+
// fn test_part2() {
31+
// assert_eq!(4, part2(&input_generator(INPUT)))
32+
// }
33+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ use aoc_runner_derive::aoc_lib;
22

33
mod day1;
44
mod day2;
5+
mod day3;
56

67
aoc_lib! { year = 2024 }

0 commit comments

Comments
 (0)