diff --git a/src/bin/day10.rs b/src/bin/day10.rs index 2d843b4..7262539 100644 --- a/src/bin/day10.rs +++ b/src/bin/day10.rs @@ -132,11 +132,26 @@ fn main() -> anyhow::Result<()> { } } } + // we can't do this so we filter the broken ones away + let start = start.unwrap(); + for (row_diff, col_diff) in [NORTH, EAST, SOUTH, WEST] { + let other = match ( + start.row.checked_add_signed(row_diff), + start.col.checked_add_signed(col_diff) + ) { + (Some(row), Some(col)) if row < grid.len() && col < grid[start.row].len() => { + Node { row, col } + }, + _ => continue + }; + if !adj.0[&other].contains(&start) { + adj.0.get_mut(&start).unwrap().remove(&other); + } + } - // 6749 is too low println!( "{:?}", - adj.dij(start.unwrap()) + adj.dij(start) .into_iter() .max_by_key(|(_, dist)| *dist) .unwrap()