diff --git a/2026/01/2026-01.run.xml b/2026/01/2026-01.run.xml new file mode 100644 index 0000000..945a2ca --- /dev/null +++ b/2026/01/2026-01.run.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/2026/01/index.test.ts b/2026/01/index.test.ts new file mode 100644 index 0000000..270e31f --- /dev/null +++ b/2026/01/index.test.ts @@ -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); + }); +}); diff --git a/2026/01/index.ts b/2026/01/index.ts new file mode 100644 index 0000000..ebc618c --- /dev/null +++ b/2026/01/index.ts @@ -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); +} diff --git a/2026/01/run.ts b/2026/01/run.ts new file mode 100644 index 0000000..88783cd --- /dev/null +++ b/2026/01/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); diff --git a/package.json b/package.json index 0312bf8..e9667f8 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "format": "prettier --write .", "check": "prettier --check .", "test": "bun test", - "test:dev": "bun test --watch 2025", + "test:dev": "bun test --watch 2026", "test:utils": "NODE_ENV=production bun test --watch --coverage utils/*" }, "devDependencies": {