Optimizations for day 16.

Don't use checks that are idempotent more than once, and reduce hashmap
use.
This commit is contained in:
2020-12-16 19:04:52 +01:00
parent 796d854838
commit 54d61e11f1

View File

@@ -86,19 +86,13 @@ impl Solution for Day16 {
let mut fixed_fields = HashMap::new();
while fixed_fields.len() != rules.len() {
for ticket in &tickets {
for (field, ranges) in &rules {
for (pos, value) in ticket.iter().enumerate() {
if pos_can_be[pos].len() <= 1 {
continue;
}
for (field, ranges) in &rules {
// If we already assigned this field, don't continue
if fixed_fields.contains_key(field) || !pos_can_be[pos].contains(field) {
continue;
}
if !ranges.iter().any(|r| r.contains(value)) {
pos_can_be[pos].remove(field);
}
@@ -106,6 +100,7 @@ impl Solution for Day16 {
}
}
while fixed_fields.len() != rules.len() {
// Fix fields that are the only option for a certain spot
for pos in 0..pos_can_be.len() {
if pos_can_be[pos].len() == 1 {