Skip to content

Commit 681ad2e

Browse files
committed
code cleanup
1 parent 0648100 commit 681ad2e

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/bin/18.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use advent_of_code::maneatingape::iter::*;
55
use advent_of_code::maneatingape::parse::*;
66
use advent_of_code::maneatingape::point::*;
77

8-
#[derive(Clone)]
8+
#[derive(Clone, Copy)]
99
enum Block {
1010
Ok,
1111
Corrupted,
@@ -35,11 +35,7 @@ fn find_shortest_path_cost(grid: &Grid<Block>) -> Option<u32> {
3535
let end_position = Point::new(grid.width - 1, grid.height - 1);
3636

3737
let mut queue = std::collections::VecDeque::new();
38-
let mut seen = Grid {
39-
width: grid.width,
40-
height: grid.height,
41-
bytes: vec![false; (grid.width * grid.height) as usize],
42-
};
38+
let mut seen = grid.same_size_with(false);
4339

4440
queue.push_front((start_position, 0));
4541
seen[start_position] = true;
@@ -65,11 +61,7 @@ fn find_shortest_path_cost(grid: &Grid<Block>) -> Option<u32> {
6561
}
6662

6763
fn generate_grid(data: &[Point], width: i32, height: i32, n: usize) -> Grid<Block> {
68-
let mut grid = Grid {
69-
width,
70-
height,
71-
bytes: vec![Block::Ok; (width * height) as usize],
72-
};
64+
let mut grid = Grid::new(width, height, Block::Ok);
7365

7466
data.iter().take(n).for_each(|&point| {
7567
grid[point] = Block::Corrupted;

0 commit comments

Comments
 (0)