From fed21d417d5cb5df923a756ef8a5672dd8fa633c Mon Sep 17 00:00:00 2001
From: Pascal Syma
Date: Thu, 4 Dec 2025 10:27:34 +0100
Subject: [PATCH] Solve 2025-04
---
2025/04/2025-04.run.xml | 7 +++++++
2025/04/index.test.ts | 21 +++++++++++++++++++++
2025/04/index.ts | 37 +++++++++++++++++++++++++++++++++++++
2025/04/run.ts | 12 ++++++++++++
4 files changed, 77 insertions(+)
create mode 100644 2025/04/2025-04.run.xml
create mode 100644 2025/04/index.test.ts
create mode 100644 2025/04/index.ts
create mode 100644 2025/04/run.ts
diff --git a/2025/04/2025-04.run.xml b/2025/04/2025-04.run.xml
new file mode 100644
index 0000000..f54ae00
--- /dev/null
+++ b/2025/04/2025-04.run.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2025/04/index.test.ts b/2025/04/index.test.ts
new file mode 100644
index 0000000..0829c1d
--- /dev/null
+++ b/2025/04/index.test.ts
@@ -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);
+ });
+});
diff --git a/2025/04/index.ts b/2025/04/index.ts
new file mode 100644
index 0000000..c325b1f
--- /dev/null
+++ b/2025/04/index.ts
@@ -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;
+}
diff --git a/2025/04/run.ts b/2025/04/run.ts
new file mode 100644
index 0000000..88783cd
--- /dev/null
+++ b/2025/04/run.ts
@@ -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);