day 2 part 1 fixes
This commit is contained in:
parent
7635b1c431
commit
31e7dcb774
1 changed files with 4 additions and 6 deletions
|
@ -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(())
|
||||
|
|
Loading…
Reference in a new issue