diff --git a/README.md b/README.md index 6cc065a..7547e5b 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,9 @@ Solutions for [Advent of Code](https://adventofcode.com/) in [Rust](https://www. | [Day 13](./src/bin/13.rs) | `12.3µs` | `15.9µs` | | [Day 14](./src/bin/14.rs) | `25.0µs` | `4.5ms` | | [Day 15](./src/bin/15.rs) | `20.4µs` | `85.9µs` | -| [Day 16](./src/bin/16.rs) | `177.4µs` | `8.2ms` | +| [Day 16](./src/bin/16.rs) | `178.8µs` | `8.1ms` | -**Total: 15.39ms** +**Total: 15.29ms** --- diff --git a/src/bin/16.rs b/src/bin/16.rs index e2bf85c..8f30373 100644 --- a/src/bin/16.rs +++ b/src/bin/16.rs @@ -32,7 +32,11 @@ fn energize_count(grid: &Grid, start: Coordinate, start_dir: Direction) -> u32 { energized[start.row * grid.width + start.col] = true; queue.push_back((start, start_dir, grid.get_tile(start))); while let Some((cur, dir, tile)) = queue.pop_front() { - for (next, next_dir, tile) in grid.neighbors(cur, dir, tile) { + for (next, next_dir) in tile + .next(dir) + .filter_map(|dir| grid.move_in_dir(cur, dir).map(|c| (c, dir))) + { + let tile = grid.get_tile(next); let i = next.row * grid.width + next.col; let was_energized = energized[i]; energized[i] = true; @@ -78,18 +82,6 @@ enum Direction { } impl Grid { - pub fn neighbors( - &self, - coord: Coordinate, - dir: Direction, - tile: Tile, - ) -> impl Iterator + '_ { - tile.next(dir).filter_map(move |dir| { - self.move_in_dir(coord, dir) - .map(|c| (c, dir, self.get_tile(c))) - }) - } - pub fn get_tile(&self, coord: Coordinate) -> Tile { self.tiles[coord.row * self.width + coord.col] }