use regex::Regex; static DAY: u8 = 3; fn main() { let input = advent::read_lines(DAY); println!("{DAY}a: {}", sum_multiplications(&input)); println!("{DAY}b: {}", 0); } fn sum_multiplications(input: &[String]) -> u32 { let re = Regex::new(r"mul\(([0-9]{1,3}),([0-9]{1,3})\)").unwrap(); let mut sum = 0; for line in input { for cap in re.captures_iter(line) { let f1 = cap[1].parse::().unwrap(); let f2 = cap[2].parse::().unwrap(); sum += f1 * f2; } } sum } #[cfg(test)] mod tests { use super::*; #[test] fn test() { let input = [ "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))" ].iter().map(|&x| String::from(x)).collect::>(); assert_eq!(sum_multiplications(&input), 161); } }