diff --git a/2024/days/03/part1/Cargo.toml b/2024/days/03/part1/Cargo.toml new file mode 100644 index 0000000..7de3509 --- /dev/null +++ b/2024/days/03/part1/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "part1" +version = "0.1.0" +edition = "2021" + +[dependencies] +regex = "1.11.1" diff --git a/2024/days/03/part1/src/main.rs b/2024/days/03/part1/src/main.rs new file mode 100644 index 0000000..0ebc80d --- /dev/null +++ b/2024/days/03/part1/src/main.rs @@ -0,0 +1,14 @@ +use regex::Regex; + +fn main() -> std::io::Result<()> { + let mut sum: u32 = 0; + let re = Regex::new(r"mul\(([0-9]*),([0-9]*)\)").unwrap(); + let hay = std::io::read_to_string(std::io::stdin()).unwrap(); + for (_, [num1, num2]) in re.captures_iter(&hay).map(|c| c.extract()) { + let num1: u32 = num1.parse().unwrap(); + let num2: u32 = num2.parse().unwrap(); + sum += num1 * num2; + } + println!("{}", sum); + Ok(()) +}