Skip to content

Commit

Permalink
d11 p1
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktoriavh committed Dec 11, 2024
1 parent c24198f commit e1f1f48
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions inputs/11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3279 998884 1832781 517 8 18864 28 0
32 changes: 32 additions & 0 deletions src/11.ts
Original file line number Diff line number Diff line change
@@ -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;
20 changes: 20 additions & 0 deletions test/11.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit e1f1f48

Please sign in to comment.