Solve 2025-04

This commit is contained in:
2025-12-04 10:27:34 +01:00
parent b43c9bba56
commit fed21d417d
4 changed files with 77 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import { replaceChar } from '../../utils/array.ts';
import { findCoordsOfDigit, getAdjacent } from '../../utils/coordinates.ts';
const PAPER_ROLL = '@';
export function solveFirst(input: string): number {
const rows = input.split('\n');
const rolls = findCoordsOfDigit(rows, PAPER_ROLL).filter(
([x, y]) =>
Object.values(getAdjacent(rows, x, y)).filter((n) => n === PAPER_ROLL)
.length < 4
);
return rolls.length;
}
export function solveSecond(input: string): number {
const rows = input.split('\n');
let removed = 0;
let removedInStep = 0;
do {
removedInStep = 0;
findCoordsOfDigit(rows, PAPER_ROLL).forEach(([x, y]) => {
if (
Object.values(getAdjacent(rows, x, y)).filter((n) => n === PAPER_ROLL)
.length < 4
) {
removedInStep++;
replaceChar(rows, x, y, 'X');
}
});
removed += removedInStep;
} while (removedInStep > 0);
return removed;
}