Solve 2025-04
This commit is contained in:
@@ -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>
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
Reference in New Issue
Block a user