Optimize 2023 day4 solution

This commit is contained in:
Timothy Warren 2023-12-11 09:47:36 -05:00
parent d3f5e06228
commit fc5c6218e5

View File

@ -86,22 +86,20 @@ impl GameMap {
None => 1, None => 1,
}; };
for _ in 0..copy_count { let add_range = id + 1..=id + match_count;
let add_range = id + 1..=id + match_count; for n in add_range {
for n in add_range { let raw_count = count_map.get(&n);
let raw_count = count_map.get(&n); if let Some(count) = raw_count {
if let Some(count) = raw_count { count_map.insert(n, *count + copy_count);
count_map.insert(n, *count + 1); let new_copy_count = match copy_map.get(&n) {
let copy_count = match copy_map.get(&n) { Some(num) => *num + copy_count,
Some(num) => *num + 1, None => copy_count,
None => 1, };
}; copy_map.insert(n, new_copy_count);
copy_map.insert(n, copy_count); } else {
} else { // No value means the value of n is greater than
// No value means the value of n is greater than // the amount of original cards
// the amount of original cards break;
break;
}
} }
} }
} }