From 97bf3cdf5d0dd73fddb7eb2f7293f8b6f1a019ae Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Sun, 3 Dec 2023 11:01:12 +0100 Subject: [PATCH] Some minor changes. --- src/main.rs | 4 ++-- src/two/mod.rs | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index c5db0d1..e60671c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,8 +8,8 @@ use one::{one_one, one_two}; use two::{two_one, two_two}; fn main() -> Result<(), AdventError> { - one_one()?; - one_two()?; + //one_one()?; + //one_two()?; two_one()?; Ok(two_two()?) } diff --git a/src/two/mod.rs b/src/two/mod.rs index 2a19d02..77e197d 100644 --- a/src/two/mod.rs +++ b/src/two/mod.rs @@ -87,20 +87,17 @@ pub fn two_one() -> Result<(), AdventError> { let max_blue = 14; for game in games.iter() { - let mut valid: bool = true; - for pull in game.pulls.iter() { - for group in pull.groups.iter() { + if game.pulls.iter().all(|pull| { + pull.groups.iter().all(|group| { match group.color { - Color::Red => if group.count > max_red { valid = false }, - Color::Green => if group.count > max_green { valid = false }, - Color::Blue => if group.count > max_blue { valid = false }, + Color::Red => group.count <= max_red, + Color::Green => group.count <= max_green, + Color::Blue => group.count <= max_blue, } - if valid == false { break }; - } - if valid == false { break }; - valid = true; + }) + }) { + sum += game.id } - if valid { sum += game.id } } Ok(println!("{}", sum))