diff --git a/2022/day_01/solution.test.ts b/2022/day_01/solution.test.ts index 51ab3db..e89ea57 100644 --- a/2022/day_01/solution.test.ts +++ b/2022/day_01/solution.test.ts @@ -1,27 +1,28 @@ +import path from "path"; import { readlines } from "../../_utils"; const solution = require("./solution"); describe("day 1: calorie counting, pt 1", () => { test("sample input", async () => { - const sample = await readlines("./day_01/sample.txt"); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); expect(solution.part1_solver(sample)).toBe(24000); }); test("submission input", async () => { - const input = await readlines("./day_01/input.txt"); + const input = await readlines(path.resolve(__dirname, "./input.txt")); expect(solution.part1_solver(input)).toBe(70613); }); }); describe("day 1: calorie counting, pt 2", () => { test("sample input", async () => { - const sample = await readlines("./day_01/sample.txt"); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); expect(solution.part2_solver(sample)).toBe(45000); }); test("submission input", async () => { - const input = await readlines("./day_01/input.txt"); + const input = await readlines(path.resolve(__dirname, "./input.txt")); expect(solution.part2_solver(input)).toBe(205805); }); }); diff --git a/2022/day_02/solution.test.ts b/2022/day_02/solution.test.ts index 34de1be..419bd09 100644 --- a/2022/day_02/solution.test.ts +++ b/2022/day_02/solution.test.ts @@ -1,27 +1,28 @@ +import path from "path"; import { readlines } from "../../_utils"; const solution = require("./solution"); describe("day 2: rock paper scissors, pt 1", () => { test("sample input", async () => { - const sample = await readlines("./day_02/sample.txt"); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); expect(solution.part1_solver(sample)).toBe(15); }); test("submission input", async () => { - const input = await readlines("./day_02/input.txt"); + const input = await readlines(path.resolve(__dirname, "./input.txt")); expect(solution.part1_solver(input)).toBe(13675); }); }); describe("day 2: rock paper scissors, pt 2", () => { test("sample input", async () => { - const sample = await readlines("./day_02/sample.txt"); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); expect(solution.part2_solver(sample)).toBe(12); }); test("submission input", async () => { - const input = await readlines("./day_02/input.txt"); + const input = await readlines(path.resolve(__dirname, "./input.txt")); expect(solution.part2_solver(input)).toBe(14184); }); }); diff --git a/2022/day_03/solution.test.ts b/2022/day_03/solution.test.ts index 52f9cd4..e395c0e 100644 --- a/2022/day_03/solution.test.ts +++ b/2022/day_03/solution.test.ts @@ -1,27 +1,28 @@ +import path from "path"; import { readlines } from "../../_utils"; const solution = require("./solution"); describe("day 3: rucksack reorganization, pt 1", () => { test("sample input", async () => { - const sample = await readlines("./day_03/sample.txt"); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); expect(solution.part1_solver(sample)).toBe(157); }); test("submission input", async () => { - const input = await readlines("./day_03/input.txt"); + const input = await readlines(path.resolve(__dirname, "./input.txt")); expect(solution.part1_solver(input)).toBe(8109); }); }); describe("day 3: rucksack reorganization, pt 2", () => { test("sample input", async () => { - const sample = await readlines("./day_03/sample.txt"); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); expect(solution.part2_solver(sample)).toBe(70); }); test("submission input", async () => { - const input = await readlines("./day_03/input.txt"); + const input = await readlines(path.resolve(__dirname, "./input.txt")); expect(solution.part2_solver(input)).toBe(2738); }); }); diff --git a/2022/day_04/solution.test.ts b/2022/day_04/solution.test.ts index 5d0bb68..9ccd0a1 100644 --- a/2022/day_04/solution.test.ts +++ b/2022/day_04/solution.test.ts @@ -1,27 +1,28 @@ +import path from "path"; import { readlines } from "../../_utils"; const solution = require("./solution"); describe("day 4: camp cleanup, pt 1", () => { test("sample input", async () => { - const sample = await readlines("./day_04/sample.txt"); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); expect(solution.part1_solver(sample)).toBe(2); }); test("submission input", async () => { - const input = await readlines("./day_04/input.txt"); + const input = await readlines(path.resolve(__dirname, "./input.txt")); expect(solution.part1_solver(input)).toBe(450); }); }); describe("day 4: camp cleanup, pt 2", () => { test("sample input", async () => { - const sample = await readlines("./day_04/sample.txt"); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); expect(solution.part2_solver(sample)).toBe(4); }); test("submission input", async () => { - const input = await readlines("./day_04/input.txt"); + const input = await readlines(path.resolve(__dirname, "./input.txt")); expect(solution.part2_solver(input)).toBe(837); }); }); diff --git a/2022/day_05/input.txt b/2022/day_05/input.txt deleted file mode 100644 index f8e58cb..0000000 --- a/2022/day_05/input.txt +++ /dev/null @@ -1,512 +0,0 @@ - [F] [Q] [Q] -[B] [Q] [V] [D] [S] -[S] [P] [T] [R] [M] [D] -[J] [V] [W] [M] [F] [J] [J] -[Z] [G] [S] [W] [N] [D] [R] [T] -[V] [M] [B] [G] [S] [C] [T] [V] [S] -[D] [S] [L] [J] [L] [G] [G] [F] [R] -[G] [Z] [C] [H] [C] [R] [H] [P] [D] - 1 2 3 4 5 6 7 8 9 - -move 3 from 5 to 2 -move 3 from 8 to 4 -move 7 from 7 to 3 -move 14 from 3 to 9 -move 8 from 4 to 1 -move 1 from 7 to 5 -move 2 from 6 to 4 -move 4 from 5 to 7 -move 1 from 3 to 6 -move 3 from 4 to 3 -move 1 from 4 to 1 -move 5 from 1 to 9 -move 1 from 4 to 6 -move 4 from 7 to 4 -move 15 from 9 to 2 -move 7 from 1 to 6 -move 3 from 3 to 5 -move 1 from 4 to 9 -move 2 from 5 to 3 -move 2 from 4 to 9 -move 4 from 1 to 6 -move 1 from 3 to 1 -move 1 from 3 to 2 -move 4 from 6 to 3 -move 24 from 2 to 8 -move 4 from 9 to 8 -move 1 from 1 to 3 -move 2 from 5 to 4 -move 1 from 2 to 4 -move 19 from 8 to 1 -move 5 from 3 to 9 -move 8 from 1 to 3 -move 3 from 4 to 1 -move 6 from 9 to 5 -move 2 from 3 to 4 -move 1 from 8 to 5 -move 2 from 4 to 6 -move 11 from 6 to 1 -move 8 from 8 to 7 -move 1 from 6 to 5 -move 13 from 1 to 3 -move 1 from 1 to 7 -move 2 from 7 to 8 -move 5 from 7 to 1 -move 2 from 8 to 4 -move 3 from 5 to 3 -move 11 from 3 to 1 -move 2 from 5 to 3 -move 2 from 5 to 3 -move 2 from 7 to 1 -move 7 from 3 to 1 -move 1 from 4 to 5 -move 1 from 6 to 4 -move 3 from 4 to 7 -move 3 from 7 to 1 -move 6 from 3 to 5 -move 1 from 5 to 9 -move 4 from 5 to 4 -move 2 from 3 to 4 -move 8 from 9 to 2 -move 5 from 4 to 6 -move 1 from 6 to 5 -move 1 from 4 to 9 -move 39 from 1 to 7 -move 7 from 2 to 6 -move 1 from 9 to 3 -move 1 from 2 to 7 -move 1 from 3 to 1 -move 5 from 7 to 3 -move 4 from 5 to 1 -move 19 from 7 to 9 -move 1 from 9 to 8 -move 1 from 9 to 7 -move 5 from 9 to 3 -move 6 from 6 to 7 -move 1 from 8 to 3 -move 4 from 1 to 4 -move 23 from 7 to 6 -move 1 from 1 to 6 -move 21 from 6 to 2 -move 3 from 4 to 8 -move 7 from 6 to 1 -move 1 from 4 to 9 -move 1 from 6 to 7 -move 6 from 1 to 2 -move 1 from 7 to 4 -move 15 from 2 to 8 -move 5 from 3 to 8 -move 22 from 8 to 7 -move 1 from 8 to 1 -move 5 from 3 to 4 -move 1 from 3 to 2 -move 1 from 1 to 2 -move 3 from 4 to 8 -move 3 from 8 to 9 -move 11 from 2 to 1 -move 2 from 1 to 4 -move 15 from 9 to 5 -move 22 from 7 to 3 -move 2 from 4 to 9 -move 3 from 4 to 2 -move 8 from 1 to 8 -move 6 from 8 to 6 -move 1 from 6 to 2 -move 3 from 6 to 9 -move 3 from 2 to 7 -move 4 from 2 to 9 -move 2 from 7 to 5 -move 1 from 1 to 7 -move 2 from 8 to 2 -move 2 from 7 to 5 -move 9 from 5 to 3 -move 8 from 5 to 2 -move 1 from 6 to 4 -move 1 from 6 to 9 -move 1 from 2 to 9 -move 2 from 5 to 1 -move 7 from 2 to 3 -move 1 from 4 to 3 -move 1 from 2 to 4 -move 5 from 3 to 4 -move 6 from 9 to 3 -move 1 from 2 to 6 -move 6 from 9 to 6 -move 2 from 1 to 8 -move 3 from 6 to 3 -move 2 from 8 to 6 -move 6 from 4 to 1 -move 14 from 3 to 9 -move 1 from 6 to 4 -move 3 from 3 to 9 -move 1 from 4 to 5 -move 10 from 9 to 6 -move 6 from 6 to 7 -move 2 from 1 to 8 -move 1 from 8 to 6 -move 16 from 3 to 2 -move 1 from 8 to 1 -move 1 from 7 to 1 -move 7 from 3 to 4 -move 1 from 6 to 5 -move 4 from 2 to 3 -move 5 from 4 to 9 -move 2 from 4 to 5 -move 4 from 7 to 4 -move 5 from 9 to 6 -move 2 from 5 to 4 -move 11 from 6 to 7 -move 1 from 6 to 8 -move 5 from 1 to 5 -move 2 from 6 to 4 -move 7 from 7 to 3 -move 1 from 8 to 6 -move 2 from 7 to 3 -move 1 from 1 to 3 -move 3 from 2 to 8 -move 9 from 2 to 5 -move 1 from 6 to 1 -move 1 from 4 to 8 -move 7 from 4 to 7 -move 8 from 5 to 6 -move 1 from 7 to 2 -move 1 from 7 to 4 -move 3 from 7 to 8 -move 1 from 2 to 3 -move 1 from 1 to 2 -move 1 from 1 to 7 -move 3 from 7 to 6 -move 11 from 6 to 2 -move 4 from 8 to 7 -move 2 from 8 to 7 -move 15 from 3 to 2 -move 7 from 9 to 4 -move 3 from 3 to 2 -move 4 from 4 to 7 -move 5 from 7 to 3 -move 3 from 4 to 6 -move 3 from 6 to 9 -move 1 from 4 to 2 -move 1 from 8 to 1 -move 2 from 3 to 7 -move 2 from 3 to 7 -move 23 from 2 to 5 -move 1 from 9 to 1 -move 1 from 7 to 9 -move 1 from 1 to 8 -move 8 from 7 to 1 -move 1 from 8 to 4 -move 1 from 4 to 2 -move 3 from 9 to 8 -move 1 from 7 to 9 -move 22 from 5 to 9 -move 1 from 8 to 5 -move 1 from 7 to 4 -move 1 from 4 to 5 -move 1 from 8 to 3 -move 2 from 9 to 3 -move 5 from 5 to 2 -move 5 from 5 to 4 -move 3 from 2 to 7 -move 1 from 7 to 3 -move 6 from 1 to 7 -move 4 from 3 to 1 -move 6 from 2 to 8 -move 1 from 5 to 6 -move 2 from 8 to 1 -move 12 from 9 to 4 -move 8 from 9 to 4 -move 1 from 2 to 9 -move 2 from 9 to 8 -move 3 from 2 to 8 -move 5 from 8 to 6 -move 7 from 7 to 1 -move 4 from 8 to 9 -move 1 from 6 to 1 -move 17 from 4 to 7 -move 1 from 2 to 4 -move 2 from 4 to 1 -move 6 from 4 to 6 -move 1 from 1 to 4 -move 7 from 1 to 5 -move 9 from 7 to 9 -move 8 from 9 to 8 -move 5 from 8 to 3 -move 1 from 5 to 6 -move 2 from 3 to 6 -move 1 from 9 to 1 -move 1 from 6 to 1 -move 10 from 6 to 1 -move 1 from 5 to 1 -move 2 from 9 to 1 -move 1 from 9 to 7 -move 2 from 6 to 8 -move 2 from 8 to 2 -move 1 from 6 to 8 -move 22 from 1 to 9 -move 9 from 7 to 5 -move 1 from 8 to 1 -move 2 from 8 to 3 -move 4 from 5 to 9 -move 1 from 8 to 3 -move 5 from 1 to 9 -move 2 from 7 to 3 -move 2 from 4 to 7 -move 1 from 8 to 5 -move 2 from 2 to 4 -move 1 from 5 to 8 -move 9 from 5 to 8 -move 2 from 7 to 5 -move 2 from 4 to 5 -move 3 from 8 to 4 -move 3 from 4 to 3 -move 2 from 8 to 6 -move 1 from 6 to 4 -move 3 from 5 to 9 -move 1 from 6 to 3 -move 12 from 3 to 5 -move 1 from 3 to 1 -move 7 from 5 to 4 -move 1 from 1 to 3 -move 1 from 8 to 1 -move 7 from 5 to 1 -move 6 from 9 to 6 -move 29 from 9 to 5 -move 2 from 4 to 6 -move 26 from 5 to 2 -move 24 from 2 to 7 -move 1 from 3 to 2 -move 8 from 1 to 7 -move 7 from 6 to 9 -move 2 from 5 to 3 -move 1 from 6 to 4 -move 3 from 8 to 5 -move 2 from 3 to 8 -move 2 from 2 to 8 -move 5 from 9 to 2 -move 27 from 7 to 2 -move 2 from 8 to 3 -move 2 from 9 to 5 -move 3 from 8 to 5 -move 2 from 7 to 4 -move 3 from 4 to 7 -move 2 from 3 to 2 -move 4 from 5 to 1 -move 5 from 7 to 2 -move 29 from 2 to 8 -move 9 from 8 to 3 -move 2 from 4 to 8 -move 7 from 3 to 2 -move 3 from 5 to 4 -move 1 from 7 to 5 -move 3 from 5 to 6 -move 2 from 1 to 8 -move 2 from 6 to 8 -move 3 from 4 to 2 -move 4 from 4 to 2 -move 1 from 6 to 8 -move 8 from 2 to 4 -move 2 from 3 to 5 -move 1 from 4 to 1 -move 3 from 1 to 2 -move 4 from 8 to 2 -move 3 from 4 to 9 -move 3 from 4 to 1 -move 2 from 9 to 5 -move 1 from 4 to 6 -move 4 from 5 to 1 -move 1 from 6 to 8 -move 1 from 9 to 3 -move 4 from 2 to 3 -move 15 from 8 to 2 -move 9 from 8 to 1 -move 1 from 3 to 9 -move 5 from 1 to 9 -move 3 from 9 to 7 -move 2 from 7 to 6 -move 3 from 3 to 2 -move 1 from 7 to 8 -move 1 from 9 to 6 -move 1 from 9 to 8 -move 2 from 8 to 2 -move 1 from 1 to 2 -move 1 from 3 to 7 -move 4 from 1 to 7 -move 19 from 2 to 5 -move 1 from 1 to 4 -move 1 from 7 to 4 -move 1 from 1 to 5 -move 3 from 1 to 4 -move 1 from 1 to 8 -move 6 from 2 to 4 -move 7 from 2 to 1 -move 2 from 7 to 9 -move 8 from 2 to 8 -move 2 from 7 to 3 -move 1 from 6 to 4 -move 10 from 4 to 6 -move 5 from 6 to 7 -move 2 from 9 to 8 -move 6 from 8 to 9 -move 1 from 2 to 3 -move 2 from 8 to 3 -move 5 from 1 to 8 -move 8 from 5 to 2 -move 8 from 8 to 7 -move 7 from 2 to 8 -move 1 from 1 to 2 -move 1 from 9 to 7 -move 1 from 4 to 2 -move 2 from 2 to 6 -move 5 from 9 to 3 -move 2 from 8 to 6 -move 2 from 3 to 9 -move 4 from 8 to 6 -move 7 from 6 to 1 -move 8 from 1 to 5 -move 1 from 8 to 7 -move 1 from 9 to 6 -move 12 from 5 to 3 -move 1 from 4 to 8 -move 2 from 9 to 5 -move 1 from 2 to 3 -move 3 from 5 to 1 -move 1 from 1 to 5 -move 21 from 3 to 8 -move 2 from 1 to 5 -move 6 from 5 to 7 -move 2 from 5 to 6 -move 10 from 6 to 9 -move 1 from 6 to 8 -move 13 from 8 to 2 -move 2 from 5 to 4 -move 2 from 4 to 3 -move 4 from 9 to 1 -move 5 from 7 to 8 -move 12 from 8 to 1 -move 5 from 9 to 6 -move 1 from 3 to 7 -move 2 from 6 to 5 -move 11 from 2 to 1 -move 1 from 8 to 4 -move 16 from 1 to 9 -move 1 from 2 to 6 -move 1 from 8 to 5 -move 12 from 9 to 3 -move 14 from 7 to 2 -move 1 from 7 to 9 -move 1 from 4 to 2 -move 1 from 7 to 5 -move 3 from 9 to 5 -move 4 from 6 to 9 -move 3 from 9 to 4 -move 1 from 8 to 4 -move 2 from 4 to 5 -move 1 from 7 to 1 -move 5 from 3 to 5 -move 2 from 4 to 2 -move 8 from 2 to 7 -move 7 from 2 to 4 -move 1 from 3 to 7 -move 3 from 9 to 7 -move 2 from 2 to 9 -move 3 from 4 to 5 -move 6 from 1 to 8 -move 6 from 1 to 5 -move 3 from 9 to 2 -move 22 from 5 to 9 -move 1 from 5 to 6 -move 2 from 2 to 3 -move 5 from 7 to 6 -move 5 from 8 to 9 -move 2 from 7 to 2 -move 20 from 9 to 4 -move 1 from 8 to 3 -move 2 from 2 to 5 -move 1 from 2 to 5 -move 15 from 4 to 8 -move 1 from 5 to 7 -move 6 from 9 to 1 -move 5 from 4 to 8 -move 2 from 4 to 8 -move 1 from 2 to 1 -move 5 from 6 to 5 -move 5 from 5 to 7 -move 1 from 9 to 8 -move 5 from 7 to 2 -move 2 from 5 to 1 -move 4 from 7 to 5 -move 1 from 5 to 9 -move 1 from 6 to 8 -move 1 from 7 to 2 -move 6 from 3 to 4 -move 3 from 5 to 7 -move 1 from 9 to 2 -move 6 from 2 to 3 -move 1 from 3 to 4 -move 13 from 8 to 9 -move 7 from 1 to 5 -move 6 from 9 to 2 -move 1 from 1 to 4 -move 6 from 2 to 3 -move 1 from 1 to 4 -move 5 from 9 to 7 -move 11 from 8 to 4 -move 7 from 7 to 3 -move 2 from 7 to 8 -move 1 from 8 to 2 -move 8 from 4 to 1 -move 2 from 1 to 6 -move 2 from 5 to 8 -move 3 from 1 to 9 -move 1 from 8 to 2 -move 11 from 3 to 2 -move 2 from 8 to 9 -move 9 from 4 to 7 -move 11 from 3 to 8 -move 7 from 9 to 6 -move 5 from 4 to 6 -move 3 from 7 to 3 -move 1 from 7 to 1 -move 5 from 7 to 6 -move 2 from 3 to 5 -move 1 from 3 to 4 -move 5 from 2 to 5 -move 1 from 1 to 7 -move 1 from 4 to 8 -move 1 from 7 to 6 -move 7 from 5 to 7 -move 2 from 5 to 7 -move 3 from 1 to 7 -move 1 from 2 to 3 -move 1 from 6 to 4 -move 1 from 3 to 4 -move 1 from 5 to 3 -move 18 from 6 to 4 -move 9 from 7 to 1 -move 14 from 4 to 6 -move 3 from 6 to 4 -move 12 from 6 to 7 -move 2 from 5 to 3 -move 3 from 7 to 4 -move 6 from 4 to 7 -move 5 from 1 to 7 -move 5 from 4 to 5 -move 5 from 2 to 1 -move 9 from 8 to 4 -move 9 from 1 to 3 -move 2 from 8 to 2 -move 4 from 2 to 4 -move 1 from 7 to 6 -move 1 from 2 to 3 -move 1 from 8 to 9 -move 1 from 6 to 9 -move 2 from 9 to 3 -move 3 from 4 to 1 -move 13 from 3 to 5 -move 12 from 5 to 1 -move 7 from 1 to 8 -move 1 from 3 to 6 -move 4 from 5 to 4 -move 1 from 5 to 2 -move 8 from 4 to 9 diff --git a/2022/day_05/sample.txt b/2022/day_05/sample.txt deleted file mode 100644 index a3199c2..0000000 --- a/2022/day_05/sample.txt +++ /dev/null @@ -1,17 +0,0 @@ - [D] -[N] [C] -[Z] [M] [P] - 1 2 3 - -move 1 from 2 to 1 -move 3 from 1 to 3 -move 2 from 2 to 1 -move 1 from 1 to 2 - - -// convention: End of Array is -["", "D", ""], ["N", "C", ""], ["Z", "M", "P"] - --> - -["Z", "N", ""], ["M", "C", "D"]. ["P", "", ""] \ No newline at end of file diff --git a/2022/day_05/solution.test.ts b/2022/day_05/solution.test.ts deleted file mode 100644 index 946f887..0000000 --- a/2022/day_05/solution.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { readlines } from "../../_utils"; - -const solution = require("./solution"); - -describe("day 5: supply stacks, pt 1", () => { - test("sample input", async () => { - const sample = await readlines("./day_05/sample.txt"); - expect(solution.part1_solver(sample)).toBe(""); - }); - - test("submission input", async () => { - const input = await readlines("./day_05/input.txt"); - expect(solution.part1_solver(input)).toBe(""); - }); -}); - -describe("day 5: supply stacks, pt 2", () => { - test("sample input", async () => { - const sample = await readlines("./day_05/sample.txt"); - expect(solution.part2_solver(sample)).toBe(0); - }); - - test("submission input", async () => { - const input = await readlines("./day_05/input.txt"); - expect(solution.part2_solver(input)).toBe(0); - }); -}); diff --git a/2022/day_05/solution.ts b/2022/day_05/solution.ts deleted file mode 100644 index 7750434..0000000 --- a/2022/day_05/solution.ts +++ /dev/null @@ -1,114 +0,0 @@ -/* ---- Day 5: Supply Stacks --- - -The expedition can depart as soon as the final supplies have been unloaded from the ships. Supplies are stored in stacks of marked crates, but because the needed supplies are buried under many other crates, the crates need to be rearranged. - -The ship has a giant cargo crane capable of moving crates between stacks. To ensure none of the crates get crushed or fall over, the crane operator will rearrange them in a series of carefully-planned steps. After the crates are rearranged, the desired crates will be at the top of each stack. - -The Elves don't want to interrupt the crane operator during this delicate procedure, but they forgot to ask her which crate will end up where, and they want to be ready to unload them as soon as possible so they can embark. - -They do, however, have a drawing of the starting stacks of crates and the rearrangement procedure (your puzzle input). For example: - - [D] -[N] [C] -[Z] [M] [P] - 1 2 3 - -move 1 from 2 to 1 -move 3 from 1 to 3 -move 2 from 2 to 1 -move 1 from 1 to 2 - -In this example, there are three stacks of crates. Stack 1 contains two crates: crate Z is on the bottom, and crate N is on top. Stack 2 contains three crates; from bottom to top, they are crates M, C, and D. Finally, stack 3 contains a single crate, P. - -Then, the rearrangement procedure is given. In each step of the procedure, a quantity of crates is moved from one stack to a different stack. In the first step of the above rearrangement procedure, one crate is moved from stack 2 to stack 1, resulting in this configuration: - -[D] -[N] [C] -[Z] [M] [P] - 1 2 3 - -In the second step, three crates are moved from stack 1 to stack 3. Crates are moved one at a time, so the first crate to be moved (D) ends up below the second and third crates: - - [Z] - [N] - [C] [D] - [M] [P] - 1 2 3 - -Then, both crates are moved from stack 2 to stack 1. Again, because crates are moved one at a time, crate C ends up below crate M: - - [Z] - [N] -[M] [D] -[C] [P] - 1 2 3 - -Finally, one crate is moved from stack 1 to stack 2: - - [Z] - [N] - [D] -[C] [M] [P] - 1 2 3 - -The Elves just need to know which crate will end up on top of each stack; in this example, the top crates are C in stack 1, M in stack 2, and Z in stack 3, so you should combine these together and give the Elves the message CMZ. - -After the rearrangement procedure completes, what crate ends up on top of each stack? -*/ - -import { emptyLines, group } from "../../_utils"; - -type Stack = string[]; // stack convention: end of array is top of stack - -class Crates { - crates: Stack[]; - - constructor(initialDiagram: string[]) { - this.crates = this.transpose(initialDiagram.map(this.loadLine)); - } - - private transpose(crates: string[][]): Stack[] { - return crates.reduce((accumulator, current) => { - return current.reduce( - (val, index) => [val, ...accumulator[index]], - [] as Stack[] - ); - }, [] as Stack[]); - } - - private loadLine(line: string): string[] { - // index of the first crate letter in the string - const firstPosition = 1; - - // crate letters are always 4 characters apart: e.g. in "[A] [B]", B's index is 4 more than A's - const letterDistance = 4; - - return line.split("").reduce((prev, currentChar, currentIndex) => { - if ( - currentChar !== "" && - (currentIndex - firstPosition) % letterDistance - ) { - console.log("HELLO? ", prev, line); - return [...prev, currentChar]; - } - }, [] as string[]); - } -} - -export function part1_solver(lines: string[]): string { - // input always separates initial crate diagram from - // the moving instructions with a blank line - const [initialCrateDiagram, rest] = group(lines, (_, l) => l.includes(" 1")); - const arrangements = rest.filter((l) => l.includes(" 1")).filter(emptyLines); - - const crates = new Crates(initialCrateDiagram); - - console.log("crates is: ", crates); - - return "1"; -} - -export function part2_solver(lines: string[]): number { - return 1; -} diff --git a/package.json b/package.json index b60d028..f3e4e07 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "main": "index.ts", "scripts": { "start": "ts-node-esm index.ts", - "test": "jest $(date +%Y)/day_$(date +%d)/solution.test.ts" + "test": "jest $(date +%Y)/day_$(date +%d)/solution.test.ts", + "test-all": "jest" }, "author": "", "license": "ISC",