From 2ee9c069d83fc8655b2dc23dabd7722e329a33d7 Mon Sep 17 00:00:00 2001 From: Dominic Date: Mon, 11 Dec 2023 14:26:38 +0100 Subject: [PATCH] day 10 part 1 --- src/bin/day10.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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()