From: Greg Burri Date: Mon, 12 Dec 2022 09:47:58 +0000 (+0100) Subject: Don't need to push visited position twice... X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=cd53fdc7171560a466815efdb344a316a06fed8c;p=advent_of_code_2022.git Don't need to push visited position twice... --- 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;