diff --git a/2023/day-13/src/part1.rs b/2023/day-13/src/part1.rs index 4ff76de..0864b00 100644 --- a/2023/day-13/src/part1.rs +++ b/2023/day-13/src/part1.rs @@ -23,13 +23,13 @@ impl Drawing { .iter() .filter(|mound| mound.x + span >= reflect_col && mound.x < reflect_col) .map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into()) - .all(|mound_reflect| self.mounds.get(&mound_reflect).is_some()) + .all(|mound_reflect| self.mounds.contains(&mound_reflect)) && self .mounds .iter() .filter(|mound| mound.x < reflect_col + span && mound.x >= reflect_col) .map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into()) - .all(|mound_reflect| self.mounds.get(&mound_reflect).is_some()) + .all(|mound_reflect| self.mounds.contains(&mound_reflect)) }) .sum::(); let row_score = (1..max_row) @@ -40,13 +40,13 @@ impl Drawing { .iter() .filter(|mound| mound.y + span >= reflect_row && mound.y < reflect_row) .map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into()) - .all(|mound_reflect| self.mounds.get(&mound_reflect).is_some()) + .all(|mound_reflect| self.mounds.contains(&mound_reflect)) && self .mounds .iter() .filter(|mound| mound.y < reflect_row + span && mound.y >= reflect_row) .map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into()) - .all(|mound_reflect| self.mounds.get(&mound_reflect).is_some()) + .all(|mound_reflect| self.mounds.contains(&mound_reflect)) }) .sum::() * 100; diff --git a/2023/day-13/src/part2.rs b/2023/day-13/src/part2.rs index 10403b7..b6d2cb2 100644 --- a/2023/day-13/src/part2.rs +++ b/2023/day-13/src/part2.rs @@ -24,14 +24,14 @@ impl Drawing { .iter() .filter(|mound| mound.x + span >= reflect_col && mound.x < reflect_col) .map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into()) - .filter(|mound_reflect| self.mounds.get(mound_reflect).is_none()) + .filter(|mound_reflect| !self.mounds.contains(mound_reflect)) .count() + self .mounds .iter() .filter(|mound| mound.x < reflect_col + span && mound.x >= reflect_col) .map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into()) - .filter(|mound_reflect| self.mounds.get(mound_reflect).is_none()) + .filter(|mound_reflect| !self.mounds.contains(mound_reflect)) .count()) == 1 }) @@ -45,14 +45,14 @@ impl Drawing { .iter() .filter(|mound| mound.y + span >= reflect_row && mound.y < reflect_row) .map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into()) - .filter(|mound_reflect| self.mounds.get(mound_reflect).is_none()) + .filter(|mound_reflect| !self.mounds.contains(mound_reflect)) .count() + self .mounds .iter() .filter(|mound| mound.y < reflect_row + span && mound.y >= reflect_row) .map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into()) - .filter(|mound_reflect| self.mounds.get(mound_reflect).is_none()) + .filter(|mound_reflect| !self.mounds.contains(mound_reflect)) .count()) == 1 }) diff --git a/2023/day-14/src/part2.rs b/2023/day-14/src/part2.rs index 9d06d66..ca20da0 100644 --- a/2023/day-14/src/part2.rs +++ b/2023/day-14/src/part2.rs @@ -57,11 +57,12 @@ pub fn part2(input: &str) -> String { let pos_in_cycle = start_of_cycle + (cycles - end_of_cycle) % len_of_cyle; - map = cache - .values() - .find_map(|(look_at_map, pos)| (*pos == pos_in_cycle).then_some(look_at_map)) - .unwrap() - .clone(); + map.clone_from( + cache + .values() + .find_map(|(look_at_map, pos)| (*pos == pos_in_cycle).then_some(look_at_map)) + .unwrap(), + ); let mut total = 0_usize; for col in 0..maxes.x { diff --git a/2023/day-23/src/part1.rs b/2023/day-23/src/part1.rs index 3b69ef8..e853dd6 100644 --- a/2023/day-23/src/part1.rs +++ b/2023/day-23/src/part1.rs @@ -60,8 +60,7 @@ pub fn part1(input: &str) -> String { .filter_map(|dir| { let next_pos = dir + *pos; node_map - .get(&next_pos) - .is_some() + .contains_key(&next_pos) .then(|| (node_map[pos], node_map[&next_pos], 1)) }) .collect::>() diff --git a/2023/day-23/src/part2.rs b/2023/day-23/src/part2.rs index fe9c701..96daeb0 100644 --- a/2023/day-23/src/part2.rs +++ b/2023/day-23/src/part2.rs @@ -47,8 +47,7 @@ pub fn part2(input: &str) -> String { .filter_map(|dir| { let next_pos = dir + *pos; node_map - .get(&next_pos) - .is_some() + .contains_key(&next_pos) .then(|| (node_map[pos], node_map[&next_pos], 1)) }) .collect::>() diff --git a/2023/day-3/src/part1.rs b/2023/day-3/src/part1.rs index f7d1f68..8fa1aea 100644 --- a/2023/day-3/src/part1.rs +++ b/2023/day-3/src/part1.rs @@ -34,7 +34,7 @@ pub fn part1(input: &str) -> String { .filter(|x| { x.generate_adjacent() .iter() - .any(|t| symbols.get(t).is_some()) + .any(|t| symbols.contains_key(t)) }) .map(|x| x.no) .sum::() diff --git a/2023/day-5/src/part1.rs b/2023/day-5/src/part1.rs index 48743d3..e982886 100644 --- a/2023/day-5/src/part1.rs +++ b/2023/day-5/src/part1.rs @@ -74,6 +74,7 @@ impl ItemMap { .expect("always") } } + /// part1 of day 5 of AOC 2023 /// /// # Arguments @@ -81,7 +82,6 @@ impl ItemMap { /// /// # Panics /// panics whenever the input isn't parsable - #[must_use] pub fn part1(input: &str) -> String { let (_input, (mut to_process, maps)) = parse_input(input).expect("aoc always has input");