diff --git a/rust/src/main.rs b/rust/src/main.rs index 66baf74..28fe4d0 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -592,7 +592,7 @@ mod day16 { .next() .unwrap() .split(",") - .flat_map(str::parse) + .map(|s| s.parse().unwrap()) .collect(); lines.next(); // "" @@ -600,7 +600,7 @@ mod day16 { let mut nearby_tickets: Vec = Vec::new(); while let Some(line) = lines.next() { - nearby_tickets.push(line.split(",").flat_map(str::parse).collect()); + nearby_tickets.push(line.split(",").map(|s| s.parse().unwrap()).collect()); } let mut part1 = 0; @@ -629,18 +629,11 @@ mod day16 { .collect(); for ticket in valid_tickets { - for (field, possibilities) in ticket.iter().zip(field_possibilities.iter_mut()) { - for rule_i in possibilities.clone().iter() { - let rule = &rules[*rule_i]; - if !((field >= &rule.ranges.0.from && field <= &rule.ranges.0.to) - || (field >= &rule.ranges.1.from && field <= &rule.ranges.1.to)) - { - possibilities - .iter() - .position(|i| i == rule_i) - .map(|i| possibilities.remove(i)); - } - } + for (&field, possibilities) in ticket.iter().zip(field_possibilities.iter_mut()) { + possibilities + .iter() + .position(|&rule_i| !rules[rule_i].validate(field)) + .map(|i| possibilities.remove(i)); } } @@ -663,7 +656,7 @@ mod day16 { } let rule = &rules[possibility].name; - if rule.starts_with("departure") { + if rule.starts_with("de") { part2 *= your_ticket[i]; } }