scan each line; uneven wall intersections are inside

This commit is contained in:
Baipyrus 2023-12-12 08:45:56 +01:00
parent 35f32b2a15
commit 6ad8f7fb31

View File

@ -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`);