1
0

shortened bit more

This commit is contained in:
2024-12-03 06:38:48 +01:00
parent af3bb05817
commit 38eae3237a

View File

@@ -13,8 +13,8 @@ fn part1(input: &str) -> RiddleResult {
let r = regex::Regex::new(r"mul\((\d{1,3}),(\d{1,3})\)").unwrap(); let r = regex::Regex::new(r"mul\((\d{1,3}),(\d{1,3})\)").unwrap();
r.captures_iter(input) r.captures_iter(input)
.map(|c| { .map(|c| {
let a: i64 = c.get(1).unwrap().as_str().parse().unwrap(); let a: i64 = c[1].parse().unwrap();
let b: i64 = c.get(2).unwrap().as_str().parse().unwrap(); let b: i64 = c[2].parse().unwrap();
a * b a * b
}) })
.sum() .sum()
@@ -31,8 +31,8 @@ fn part2(input: &str) -> RiddleResult {
"do()" => (true, result), "do()" => (true, result),
"don't()" => (false, result), "don't()" => (false, result),
_ => { _ => {
let a: i64 = c.get(1).unwrap().as_str().parse().unwrap(); let a: i64 = c[1].parse().unwrap();
let b: i64 = c.get(2).unwrap().as_str().parse().unwrap(); let b: i64 = c[2].parse().unwrap();
(enabled, result + if enabled { a * b } else { 0 }) (enabled, result + if enabled { a * b } else { 0 })
} }
} }