From 6ad8f7fb319ea78f585dda0c93c6232a254e2413 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Tue, 12 Dec 2023 08:45:56 +0100 Subject: [PATCH] scan each line; uneven wall intersections are inside --- Day10/Part2.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Day10/Part2.js b/Day10/Part2.js index c8c2457..8fe773c 100644 --- a/Day10/Part2.js +++ b/Day10/Part2.js @@ -80,7 +80,30 @@ while (open.length > 0) { open.push(next); } } + console.log(input.map((e) => e.join("")).join("\n")); +let count = 0; +input.forEach((l, j) => { + let wallLength = 0; + let lastWall = false; + let intersections = 0; + l.forEach((c, i) => { + const isWall = c === "+"; + if (isWall) { + if (!lastWall) { + intersections++; + lastWall = true; + } + wallLength++; + return; + } + if (lastWall && wallLength > 1) intersections++; + wallLength = 0; + lastWall = false; + if (intersections % 2 === 1 && l.slice(i + 1).includes("+")) count++; + }); +}); +console.log(count); const t1 = performance.now(); console.log(`Runtime: ${t1 - t0}ms`);