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))