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
+7
View File
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="2025-04" type="BunRunConfiguration">
<option name="program" value="2025/04/run.ts" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
+21
View File
@@ -0,0 +1,21 @@
import { describe, expect, it } from 'bun:test';
import { solveFirst, solveSecond } from './index.ts';
describe('2025-04', () => {
const testInput = `..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.`;
it('first', () => {
expect(solveFirst(testInput)).toBe(13);
});
it('second', () => {
expect(solveSecond(testInput)).toBe(43);
});
});
+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;
}
+12
View File
@@ -0,0 +1,12 @@
import { join } from 'path';
import { solveFirst, solveSecond } from './index.ts';
const input = await Bun.file(join(__dirname, 'input.txt')).text();
const firstAnswer = solveFirst(input);
console.log(firstAnswer);
const secondAnswer = solveSecond(input);
console.log(secondAnswer);