From 14c6eec96f31ca4c3e15db646891f8e29ad26ec0 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sat, 27 Jan 2024 23:55:08 +0100 Subject: [PATCH] a* neighbor calculations --- Day17/Part1.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Day17/Part1.js b/Day17/Part1.js index 5ebc725..b5dbb96 100644 --- a/Day17/Part1.js +++ b/Day17/Part1.js @@ -44,6 +44,17 @@ while (open.length > 0) { if (!input[ny]) continue; const next = input[ny][nx]; if (!next || closed.includes(next)) continue; + + const nd = current.g + next.c; + if (open.includes(next)) { + if (nd < next.g) + next.g = nd; + continue; + } + + next.g = nd; + next.h = man_dist(next, end); + open.push(next); } } console.log(end.g);