diff --git a/src/day15/2.rs b/src/day15/2.rs index 7caef88..e899296 100644 --- a/src/day15/2.rs +++ b/src/day15/2.rs @@ -2,9 +2,6 @@ #![feature(test)] extern crate test; - -use fxhash::FxHashSet; - const INPUTS: [&str; 2] = [ "########## #..O..O.O# @@ -147,7 +144,6 @@ fn validate_move(grid: &mut Bitmap, walls: &Bitmap, x: i64, y: i64, direction: i } 0 | 2 => { - let mut seen = FxHashSet::default(); let mut to_move = vec![]; let starting_point = if grid.get_left(x,y) { @@ -157,7 +153,6 @@ fn validate_move(grid: &mut Bitmap, walls: &Bitmap, x: i64, y: i64, direction: i } else { return false; }; - seen.insert(starting_point); to_move.push(starting_point); let mut last_checked = 0; @@ -177,11 +172,7 @@ fn validate_move(grid: &mut Bitmap, walls: &Bitmap, x: i64, y: i64, direction: i continue; }; - if seen.contains(&p) { - continue; - } to_move.push(p); - seen.insert(p); } last_checked = i+1; } @@ -191,6 +182,9 @@ fn validate_move(grid: &mut Bitmap, walls: &Bitmap, x: i64, y: i64, direction: i let mut grida = grid.clone(); while let Some(coord) = to_move.pop() { + if coord.iter().all(|x| !grida.get(x.0,x.1)) { + continue; + } if coord.iter().any(|x| grida.get(x.0+delta.0, x.1+delta.1) || walls.get(x.0+delta.0, x.1+delta.1)) { return false; }