day 2 part 1 fixes

This commit is contained in:
Rasmus Moorats 2023-12-04 17:32:47 +02:00
parent 7635b1c431
commit 31e7dcb774
Signed by: xx
GPG key ID: FE14255A6AE7241C

View file

@ -11,7 +11,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let input = io::read_to_string(io::stdin())?;
let sum = input.lines().enumerate().map(|(i, line)| {
let game: Vec<Show> = line.split(":").last().unwrap().split(";").map(|shown| {
if line.split(":").last().unwrap().split(";").map(|shown| {
let mut show = Show { red: 0, green: 0, blue: 0 };
for color in shown.split(",") {
let mut color_iter = color.split_whitespace();
@ -24,11 +24,9 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}
show
}).collect();
(i + 1, game)
}).filter(|(_, game)|
game.iter().all(|show| show.red <= 12 && show.green <= 13 && show.blue <= 14)
).map(|(i, _)| i).sum::<usize>();
}).all(|show| show.red <= 12 && show.green <= 13 && show.blue <= 14)
{ i + 1 } else { 0 }
}).sum::<usize>();
println!("{}", sum);
Ok(())