diff --git a/aoc2021/src/day09.rs b/aoc2021/src/day09.rs index 9d21357..8b0d09a 100644 --- a/aoc2021/src/day09.rs +++ b/aoc2021/src/day09.rs @@ -88,10 +88,8 @@ impl HeightMap { } self.filled_points.insert((x, y)); - let neighbours: Vec<_> = self.neighbours(x, y).collect(); - neighbours - .iter() - .map(|&(nx, ny)| self.fill_basin(nx, ny)) + self.neighbours(x, y) + .map(|(nx, ny)| self.fill_basin(nx, ny)) .sum::() + 1 } @@ -105,11 +103,13 @@ impl HeightMap { }) } - fn neighbours(&self, x: usize, y: usize) -> impl Iterator + '_ { + fn neighbours(&self, x: usize, y: usize) -> impl Iterator + 'static { + let width = self.width; + let height = self.height; Neighbour::ALL .iter() .copied() - .filter_map(move |neighbour| neighbour.apply(x, y, self.width, self.height)) + .filter_map(move |neighbour| neighbour.apply(x, y, width, height)) } fn risk_level(&self, x: usize, y: usize) -> u64 {