From 5d0286ac0ac4b2d7f17b6c73703b9fd2bfc57bc2 Mon Sep 17 00:00:00 2001 From: martapanc Date: Sun, 8 Dec 2024 17:17:04 +0100 Subject: [PATCH] Refactor --- 2024/src/2024/day04/day04.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/2024/src/2024/day04/day04.ts b/2024/src/2024/day04/day04.ts index c1ddb99..76d6211 100644 --- a/2024/src/2024/day04/day04.ts +++ b/2024/src/2024/day04/day04.ts @@ -29,13 +29,10 @@ function solve_XMAS_Crosswords(grid: Grid): number { grid.forEach((value, cell) => { if (value === 'X') { - const neighbors = getNeighbors(Coord.deserialize(cell), grid, true); - if (neighbors.some(n => n === 'M')) { - const all = getAllCandidates(Coord.deserialize(cell), grid); + const all = getAllCandidates(Coord.deserialize(cell), grid); - const localXmasCount: number = all.filter(s => s === 'XMAS').length; - xmasCount += localXmasCount; - } + const localXmasCount: number = all.filter(s => s === 'XMAS').length; + xmasCount += localXmasCount; } }); @@ -65,9 +62,7 @@ function getAllCandidates(cell: Coord, grid: Grid) { .filter(c => grid.has(c.serialize())) .map(c => grid.get(c.serialize())); - if (values.length === 4) { - candidates.push(values.join('')); - } + candidates.push(values.join('')); }); return candidates;