From 4b61a2ed243c270f6e10c1f79fd42a7c95bfa736 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sat, 27 Jan 2024 23:53:01 +0100 Subject: [PATCH] prepare scanning neighbors --- Day17/Part1.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Day17/Part1.js b/Day17/Part1.js index 7ad3c8d..5ebc725 100644 --- a/Day17/Part1.js +++ b/Day17/Part1.js @@ -33,6 +33,18 @@ while (open.length > 0) { const current = open.splice(record.index, 1)[0]; closed.push(current); if (current === end) break; + + for (let j = -1; j < 2; j++) + for (let i = -1; i < 2; i++) { + if (!(i === 0 ^ j === 0)) continue; + + const nx = current.x + i; + const ny = current.y + j; + + if (!input[ny]) continue; + const next = input[ny][nx]; + if (!next || closed.includes(next)) continue; + } } console.log(end.g);