Optimize 2023 day4 solution
This commit is contained in:
parent
d3f5e06228
commit
fc5c6218e5
@ -86,22 +86,20 @@ impl GameMap {
|
||||
None => 1,
|
||||
};
|
||||
|
||||
for _ in 0..copy_count {
|
||||
let add_range = id + 1..=id + match_count;
|
||||
for n in add_range {
|
||||
let raw_count = count_map.get(&n);
|
||||
if let Some(count) = raw_count {
|
||||
count_map.insert(n, *count + 1);
|
||||
let copy_count = match copy_map.get(&n) {
|
||||
Some(num) => *num + 1,
|
||||
None => 1,
|
||||
};
|
||||
copy_map.insert(n, copy_count);
|
||||
} else {
|
||||
// No value means the value of n is greater than
|
||||
// the amount of original cards
|
||||
break;
|
||||
}
|
||||
let add_range = id + 1..=id + match_count;
|
||||
for n in add_range {
|
||||
let raw_count = count_map.get(&n);
|
||||
if let Some(count) = raw_count {
|
||||
count_map.insert(n, *count + copy_count);
|
||||
let new_copy_count = match copy_map.get(&n) {
|
||||
Some(num) => *num + copy_count,
|
||||
None => copy_count,
|
||||
};
|
||||
copy_map.insert(n, new_copy_count);
|
||||
} else {
|
||||
// No value means the value of n is greater than
|
||||
// the amount of original cards
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user