From cd53fdc7171560a466815efdb344a316a06fed8c Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Mon, 12 Dec 2022 10:47:58 +0100 Subject: [PATCH] Don't need to push visited position twice... --- src/day12.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/day12.rs b/src/day12.rs index 1e03ed3..ee08a24 100644 --- a/src/day12.rs +++ b/src/day12.rs @@ -52,6 +52,8 @@ pub fn nb_steps(hm: &Heightmap, path: Path) -> i32 { positions }; + visited[hm.end.0][hm.end.1] = 0; + loop { step = step + 1; for (i, j) in positions.drain(..) { @@ -59,7 +61,6 @@ pub fn nb_steps(hm: &Heightmap, path: Path) -> i32 { return step; } - visited[i][j] = step; for (ni, nj) in neighbors(i, j) { if visited[ni][nj] == -1 && hm.elevations[i][j] - hm.elevations[ni][nj] <= 1 { visited[ni][nj] = step; -- 2.45.2