day 3: part 1: rust
This commit is contained in:
parent
160145a983
commit
6160b15a1f
|
@ -0,0 +1,7 @@
|
||||||
|
[package]
|
||||||
|
name = "part1"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
regex = "1.11.1"
|
|
@ -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(())
|
||||||
|
}
|
Loading…
Reference in New Issue