Solve 2026-01

This commit is contained in:
2026-12-02 16:20:32 +01:00
parent 106c16ee1e
commit 82adaf36ac
5 changed files with 73 additions and 1 deletions
+7
View File
@@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="2026-01" type="BunRunConfiguration">
<option name="program" value="2026/01/run.ts" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
+32
View File
@@ -0,0 +1,32 @@
import { describe, expect, it } from 'bun:test';
import { solveFirst, solveSecond } from './index.ts';
describe('2026-01', () => {
const testInput = `57
57
55
57
76
78
57
45
43
78
43
76
43
78
57
45
57
76
43
43
76`;
it('first', () => {
expect(solveFirst(testInput)).toBe(186276);
});
it('second', () => {
expect(solveSecond(testInput)).toBe(193050);
});
});
+21
View File
@@ -0,0 +1,21 @@
import { groupBy, multBy } from '../../utils/array.ts';
export function solveFirst(input: string): number {
const numbers = groupBy(input.split('\n').map(Number), (n) => n).toSorted(
(a, b) => b.elements.length - a.elements.length
);
const top3 = numbers.slice(0, 3);
return multBy(top3, (e) => e.key);
}
export function solveSecond(input: string): number {
const numbers = groupBy(input.split('\n').map(Number), (n) => n).toSorted(
(a, b) => a.elements.length - b.elements.length
);
const top3 = numbers.slice(0, 3);
return multBy(top3, (e) => e.key);
}
+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);