Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Dec 8, 2024
1 parent adadbd6 commit 5d0286a
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions 2024/src/2024/day04/day04.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5d0286a

Please sign in to comment.