Skip to content

Commit 2094b7b

Browse files
committed
feat: 2025 Day 3
1 parent 760ade7 commit 2094b7b

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

2025/day/3/part/1/solve.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import solve from "./solve.ts";
2+
3+
import { assertEquals } from "@std/assert";
4+
5+
Deno.test("example", () => {
6+
const input = `\
7+
987654321111111
8+
811111111111119
9+
234234234234278
10+
818181911112111`;
11+
12+
assertEquals(solve(input), 357);
13+
});

2025/day/3/part/1/solve.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function solve(input: string) {
2+
const banks = input.split("\n").map((line) => Array.from(line, Number));
3+
let sum = 0;
4+
for (const bank of banks) {
5+
const max = Math.max(...bank.slice(0, -1));
6+
const indexOfMax = bank.findIndex((value) => value === max);
7+
sum += max * 10 + Math.max(...bank.slice(indexOfMax + 1));
8+
}
9+
return sum;
10+
}

2025/day/3/part/2/solve.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import solve from "./solve.ts";
2+
3+
import { assertEquals } from "@std/assert";
4+
5+
Deno.test("example", () => {
6+
const input = `\
7+
987654321111111
8+
811111111111119
9+
234234234234278
10+
818181911112111`;
11+
12+
assertEquals(solve(input), 3121910778619);
13+
});

2025/day/3/part/2/solve.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default function solve(input: string) {
2+
const banks = input.split("\n").map((line) => Array.from(line, Number));
3+
let sum = 0;
4+
for (let bank of banks) {
5+
const digits = [Math.max(...bank.slice(0, -11))];
6+
while (digits.length < 12) {
7+
bank = bank.slice(bank.indexOf(digits[digits.length - 1]) + 1);
8+
digits.push(Math.max(...bank.slice(0, bank.length - 11 + digits.length)));
9+
}
10+
sum += +digits.join("");
11+
}
12+
return sum;
13+
}

0 commit comments

Comments
 (0)