diff --git a/inputs/11.txt b/inputs/11.txt new file mode 100644 index 0000000..ec45afc --- /dev/null +++ b/inputs/11.txt @@ -0,0 +1 @@ +3279 998884 1832781 517 8 18864 28 0 \ No newline at end of file diff --git a/src/11.ts b/src/11.ts new file mode 100644 index 0000000..97b84d0 --- /dev/null +++ b/src/11.ts @@ -0,0 +1,32 @@ +function solution(input: string): { part1: string; part2: string } { + let result1 = 0; + let result2 = 0; + + const lines = input.split(" "); + const totalBlinkAmount = 25; + let stones: string[] = [...lines]; + + for (let i = 0; i < totalBlinkAmount; i++) { + stones = stones.flatMap((line) => { + if (line === "0") { + return "1"; + } + if (line.length % 2 === 0) { + const half = line.length / 2; + const firstHalf = line.slice(0, half); + const secondHalf = line.slice(half); + return [Number(firstHalf).toString(), Number(secondHalf).toString()]; + } + return (Number(line) * 2024).toString(); + }); + } + + result1 = stones.length; + + return { + part1: result1.toString(), + part2: result2.toString(), + }; +} + +export default solution; diff --git a/test/11.test.ts b/test/11.test.ts new file mode 100644 index 0000000..3df0d22 --- /dev/null +++ b/test/11.test.ts @@ -0,0 +1,20 @@ +import { expect, test, describe } from "bun:test"; +import solution from "../src/11"; + +const EXAMPLE_1 = `125 17`; +const RESULT_1 = "55312"; + +const EXAMPLE_2 = EXAMPLE_1; +const RESULT_2 = "31"; + +describe("Day 11", () => { + test("Part 1", () => { + const result = solution(EXAMPLE_1); + expect(result.part1).toBe(RESULT_1); + }); + + test("Part 2", () => { + const result = solution(EXAMPLE_2); + expect(result.part2).toBe(RESULT_2); + }); +});