day 10 part 1

This commit is contained in:
Dominic 2023-12-11 14:26:38 +01:00
parent bb03ac3dca
commit 2ee9c069d8
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -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!( println!(
"{:?}", "{:?}",
adj.dij(start.unwrap()) adj.dij(start)
.into_iter() .into_iter()
.max_by_key(|(_, dist)| *dist) .max_by_key(|(_, dist)| *dist)
.unwrap() .unwrap()