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: https://git.euphorik.ch/?a=commitdiff_plain;h=21d1244e6b5f4a8bbf46f38668feb2f5c1b7a2cd;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;