summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2022-12-23 15:55:39 +0200
committerJustin Wernick <justin@worthe-it.co.za>2022-12-23 15:55:39 +0200
commit1970b5b3472398ae6a96ad8720096e941f71a062 (patch)
treeffb8353331cf12d11cd3c9b537c5be5d296c94cb
parent0071f556d6b6fdac0fb6c7879e92932d80418f0f (diff)
Clippy-driven cleanup
-rw-r--r--2022/src/bin/day_23.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/2022/src/bin/day_23.rs b/2022/src/bin/day_23.rs
index 1267431..44483a5 100644
--- a/2022/src/bin/day_23.rs
+++ b/2022/src/bin/day_23.rs
@@ -24,7 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
{
- let mut elves_2 = elves.clone();
+ let mut elves_2 = elves;
for round in 1.. {
if !elves_2.process_round() {
dbg!(round);
@@ -98,17 +98,23 @@ impl ElfMap {
// phase 1: figure out where each elf wants to move
for elf in &self.elves {
- if let Some(destination) = self.find_elf_move(&elf) {
- if elf_moves.contains_key(&destination) {
- elf_moves.remove(&destination);
- conflict_moves.insert(destination);
- } else if !conflict_moves.contains(&destination) {
- elf_moves.insert(destination, elf.clone());
+ if let Some(destination) = self.find_elf_move(elf) {
+ use std::collections::btree_map::Entry;
+ match elf_moves.entry(destination) {
+ Entry::Occupied(elf_move_entry) => {
+ conflict_moves.insert(elf_move_entry.key().clone());
+ elf_move_entry.remove_entry();
+ }
+ Entry::Vacant(elf_move_entry) => {
+ if !conflict_moves.contains(elf_move_entry.key()) {
+ elf_move_entry.insert(elf.clone());
+ }
+ }
}
}
}
- let any_elf_moved = elf_moves.len() > 0;
+ let any_elf_moved = !elf_moves.is_empty();
// phase 2: move the elves
for (dest, src) in elf_moves {