diff --git a/day_01/input.txt b/2022/day_01/input.txt similarity index 100% rename from day_01/input.txt rename to 2022/day_01/input.txt diff --git a/day_01/sample.txt b/2022/day_01/sample.txt similarity index 100% rename from day_01/sample.txt rename to 2022/day_01/sample.txt diff --git a/day_01/solution.test.ts b/2022/day_01/solution.test.ts similarity index 94% rename from day_01/solution.test.ts rename to 2022/day_01/solution.test.ts index 22564a5..51ab3db 100644 --- a/day_01/solution.test.ts +++ b/2022/day_01/solution.test.ts @@ -1,4 +1,4 @@ -import { readlines } from "../_utils"; +import { readlines } from "../../_utils"; const solution = require("./solution"); diff --git a/day_01/solution.ts b/2022/day_01/solution.ts similarity index 99% rename from day_01/solution.ts rename to 2022/day_01/solution.ts index 098fa9f..94bccea 100644 --- a/day_01/solution.ts +++ b/2022/day_01/solution.ts @@ -43,7 +43,7 @@ In case the Elves get hungry and need extra snacks, they need to know which Elf Find the Elf carrying the most Calories. How many total Calories is that Elf carrying? */ -import { group, sum } from "../_utils"; +import { group, sum } from "../../_utils"; const groupSnacksByElf = (lines: string[]): string[][] => group(lines, (_, line) => line === "", false); diff --git a/day_02/input.txt b/2022/day_02/input.txt similarity index 100% rename from day_02/input.txt rename to 2022/day_02/input.txt diff --git a/day_02/sample.txt b/2022/day_02/sample.txt similarity index 100% rename from day_02/sample.txt rename to 2022/day_02/sample.txt diff --git a/day_02/solution.test.ts b/2022/day_02/solution.test.ts similarity index 94% rename from day_02/solution.test.ts rename to 2022/day_02/solution.test.ts index 17ce2e9..34de1be 100644 --- a/day_02/solution.test.ts +++ b/2022/day_02/solution.test.ts @@ -1,4 +1,4 @@ -import { readlines } from "../_utils"; +import { readlines } from "../../_utils"; const solution = require("./solution"); diff --git a/day_02/solution.ts b/2022/day_02/solution.ts similarity index 99% rename from day_02/solution.ts rename to 2022/day_02/solution.ts index 4b45f90..9f6e088 100644 --- a/day_02/solution.ts +++ b/2022/day_02/solution.ts @@ -30,7 +30,7 @@ In this example, if you were to follow the strategy guide, you would get a total What would your total score be if everything goes exactly according to your strategy guide? */ -import { emptyLines, sum } from "../_utils"; +import { emptyLines, sum } from "../../_utils"; export function part1_solver(lines: string[]): number { const score_map = { diff --git a/day_03/input.txt b/2022/day_03/input.txt similarity index 100% rename from day_03/input.txt rename to 2022/day_03/input.txt diff --git a/day_03/sample.txt b/2022/day_03/sample.txt similarity index 100% rename from day_03/sample.txt rename to 2022/day_03/sample.txt diff --git a/day_03/solution.test.ts b/2022/day_03/solution.test.ts similarity index 94% rename from day_03/solution.test.ts rename to 2022/day_03/solution.test.ts index 210c833..52f9cd4 100644 --- a/day_03/solution.test.ts +++ b/2022/day_03/solution.test.ts @@ -1,4 +1,4 @@ -import { readlines } from "../_utils"; +import { readlines } from "../../_utils"; const solution = require("./solution"); diff --git a/day_03/solution.ts b/2022/day_03/solution.ts similarity index 99% rename from day_03/solution.ts rename to 2022/day_03/solution.ts index bd5560a..cf8224e 100644 --- a/day_03/solution.ts +++ b/2022/day_03/solution.ts @@ -35,7 +35,7 @@ In the above example, the priority of the item type that appears in both compart Find the item type that appears in both compartments of each rucksack. What is the sum of the priorities of those item types? */ -import { emptyLines, group, sum } from "../_utils"; +import { emptyLines, group, sum } from "../../_utils"; /** * diff --git a/day_04/input.txt b/2022/day_04/input.txt similarity index 100% rename from day_04/input.txt rename to 2022/day_04/input.txt diff --git a/day_04/sample.txt b/2022/day_04/sample.txt similarity index 100% rename from day_04/sample.txt rename to 2022/day_04/sample.txt diff --git a/day_04/solution.test.ts b/2022/day_04/solution.test.ts similarity index 94% rename from day_04/solution.test.ts rename to 2022/day_04/solution.test.ts index 4af9934..5d0bb68 100644 --- a/day_04/solution.test.ts +++ b/2022/day_04/solution.test.ts @@ -1,4 +1,4 @@ -import { readlines } from "../_utils"; +import { readlines } from "../../_utils"; const solution = require("./solution"); diff --git a/day_04/solution.ts b/2022/day_04/solution.ts similarity index 98% rename from day_04/solution.ts rename to 2022/day_04/solution.ts index 7110e96..6d78441 100644 --- a/day_04/solution.ts +++ b/2022/day_04/solution.ts @@ -45,7 +45,7 @@ Some of the pairs have noticed that one of their assignments fully contains the In how many assignment pairs does one range fully contain the other? */ -import { emptyLines, sum } from "../_utils"; +import { emptyLines, sum } from "../../_utils"; class Range { min: number; diff --git a/2022/day_05/input.txt b/2022/day_05/input.txt new file mode 100644 index 0000000..f8e58cb --- /dev/null +++ b/2022/day_05/input.txt @@ -0,0 +1,512 @@ + [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 new file mode 100644 index 0000000..a3199c2 --- /dev/null +++ b/2022/day_05/sample.txt @@ -0,0 +1,17 @@ + [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 new file mode 100644 index 0000000..946f887 --- /dev/null +++ b/2022/day_05/solution.test.ts @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..7750434 --- /dev/null +++ b/2022/day_05/solution.ts @@ -0,0 +1,114 @@ +/* +--- 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/2023/day_01/input.txt b/2023/day_01/input.txt new file mode 100644 index 0000000..df09d64 --- /dev/null +++ b/2023/day_01/input.txt @@ -0,0 +1,1000 @@ +six1mpffbnbnnlxthree +4eight3one92 +9nine2xnhvjtjlzj48 +jxrbrt4jmnmlonesznvbjrsn +nsvkljgpfn77pvfour5j +fourlkgmnnzncht75 +shqmhnlbjjvskone6two78 +qjgcxccgthree85five +eight7sbdbgqgcfive3two +eight878nckqdt3pgzc +pkdrhksqdhrvhg5 +nine7four7one2 +9fives +fplzzhthreethree7sqnsmrljgsmnpktfkhzdpqfkone +hqrcls33sevensevennine +four4m +seven331fivekfrqbd +ninechvkpthreefive8tlmfclr +8954bxsqntndjmonenx5 +nine7km +seven588sevenxffivethreehkrczrlm +3cmjzjmhone +jfgr2fourtflvttr +qpplcgvklzztqjkbbnfiveftcqmlrqnd824 +ttsgz9 +9eightthreeonezrninetwo +pbccq6onefoureightbkvgvtm3 +9tworrchzdzfthreefgksrzjpdq +chcjdxbninejtwo1nineszf2one +ronecfcdlsqgfvlxj217 +three4onex1 +8nrhcn3zgsgn3239 +3tczzbrvdm6tphb32 +85threecnqsscqklhsix +5foureightnine57nshjbgrv +1fourpcgljhlx5 +v632eightnnjrjl +zlpfive6xthreeczrknclqdtfiveseven +6ninekbdmjqrktwo2 +threetwofourlqjnmnine767 +8two5mbs3eightthreethreelvhcgrd +zntoneightfour1lcbzfhm4msneight7 +7eight5eightone +8rpbfqb44 +rfninelkclkflsjsrb3 +jzxlngk1 +5zsnxfdt82qmszx +75threetcvbmhplqmhrcztsghctvsvrhkftwo +grtwosnjvrpx76 +69two1tdsgbgbprs7 +vrsrmdngjpn2nine +onesix44vgdtwo +phtfxkmbfbm61one4pxnvnvld6 +hfsmptwo6dtlnfnmtmrpgmr +jgrbttcmfkkbrdeight846dzgdjxd3 +jdsfprdmhpvzqbgjdgdvkhmtqzxgm8flhxfive +qj36gfj +3twonine +bszc6bvfkfjbbh +4sevenfive4one +fourhxkhxtvtblsevenonekgnpnjqq46ctvmzkqvxdl +6989hvr4258 +seveneightfivegbzczonerqkdvsfour6 +326sevenoneeightfour +41five8one3 +zrtnkqtqfive91bxfctxnk +t226n6xnrdeight5 +one5onetlzbbxchgfhzgx +five5seven8 +1pnvdbvl2zrjpbkbpthree +tlctwone39zfdqtnjshzjrqkcdnjnszrdfive +snklklhpcclkrtkn2eight15three8 +7threeplhsfsevenbgbbnineftvjbnvxpsm +5dtxxthtphbnc +six7four +djsvntknhnqv2qrvnrz +twosevenbzvfzpbonenine5 +1tq2eightseven3sixvjvnkqq4 +z55 +4mthgcrfbcvphfmglvcjsl8pctb +6jgptkgcl43bthreetjfxchtxlf5 +5zxgktvdnninenine9 +lhdfivevxrgpkpzrzjlg5mk +oneseven4seven6njmkvkpjmg +cblmbxlthtfqfk59three8 +xxcnvsfour298mqqrbcn +lbvmgdpgbd3hgmpthreefourjbdbfvvv5vfqrd4 +vsxshfhftrgpstxtj94xnxrntxnlcgtdjtqpbmh +six7fournrmdgzldndnrgrkxlbtdonemjftskhhm4 +1sixtwoseventwofivezbsdvdqncffourkknlsx +78mqspvdsb2 +teight4skkdlfcsrc38jfjtmfour2 +3pgbppzbmlbsevensix533one +hzrfpeighthjrf4kqttngxfivefivehzvxnzfk4 +18zldlpktnceight +six6lvnt6k +28sixs +348lmkg9one4 +4ninesnqqzoneltjhsjjbnp2 +rckbvndsjm99six2nine +eight5vhjvgrrthreetwo6 +2fourseven1oneights +7threeonethreex +662dvrszddqqtwoeightsixeight9 +xftcvpmkl2threecdqsix48kgfktcdn8 +3rcgdrjcnmb +4three5 +two3twotwonine7ljonezh +17mdbr9ninehhs3 +nchgkdvbm8onebhdtmgdgkqjfour +1eightpqbslptjfgninenine72 +1ghpjmc4q +245seventgftbfkbnztwoone +94gxjjlptflxsvsrxxone +seven3three +7foureight +mxgc6 +sixthree6rrdntczlrrnsnine +9three4nd1eightseven +ndeightwosnlvkv8jdllrtwo741 +threefour6bkscthreeeight +hffoneight96vqkbsgpzvn3sixtxh4ckjlm3 +vc6tnine5mfplhklmv +zoneight35ninefour1q5ssmjtf +rkblg8tzdjhrsdxbcx +kgvqtxzjr56psfour9 +6dtbh67five +qjx4two2ls +hfstd58three65twosbxll +g2twosixvlvtt +sevensix4nineonetvfcctgnj +tkjbktckztwozzstwo7jgxbxxrkzx +8gftwosjkhqxvfpqrsrseven +sevenkphl9eight91onesxjvtfdccd +lcrvslcc6bhzlcmz +bbxdjdfprnjtxhsevendzsbczc6one +one5m29 +h3one +sixtjdgzvfqpjvdthree421x7 +eightfiveeight8sbmspqltvsxsix +four8two +5sixfour94961 +9two6onenjfsnqnmfc +fivethree8six3l +1twokzqnbclbqgtbeightrtwo +7csgktwooneone +75nine8two +fourrj5tfdrlgdzrfptxvnine +four4seven5eight +6onesixtpsgqgk5seven +qpznmcmfgpfqmzvkthdseven93threersxsktrkk99 +587nine6eightseventhreeqmjv +zfssixvkhtlcmltwo7 +8bqvgfnzg +6l2eighttjtgrj1knrtjqrpjd +lmjbs6ninethreeeight58 +1ktxhfzkgrfmtthree +xtmfsxsdfgfivethreefour9fnjcmbdz +vlhlhzsevenonelhql285xccp +3172bndlm4sevenpnz +6sbzqfftqnfourhktmxxqkthreepzkjvfxxfour +sevenfoursix544nineqr +9eightsevensevenqrxjzmmfjnd +ceightwogntfttkkkdpsq3 +gpmtpbchjdpgmkone8sixmhm53 +ndfz9twoonelprmtwoslvvp3 +njrtr14sevenninevmnbone +1q +seven1eight +svstnvxdbmseven9pbfrsgvlhd398 +3ninefivelbcxcfcc +9njgmxpeightpqgj +three6636bbqrtxprjb4onetkkgxxmtv +7ssrrsfourfournine +4one1eightzgcpkgbpgmsevenninetwonetk +threelpmgdpmmsevenxkphrddr5two9 +plpzz4 +91fiveg +fournnjzsnrqzbdggldr9 +llnsix5sevenfive45threeone +xxnftztcbzrptthreervfiveseven9sevenlnxhzvk +glceightwo4eightnineeight9fpbp +six6eightfour1fjlmmqlqszvkbspshcvnjlxfvmm +6sevenfourmnv1qcf2khfjclcsx +fivebsvvnhgcp6jdqrcfreightwohfh +9eight5onerjvcdct5 +jb81onefournine35tftlzn +59sevenpcfninevtrrrhmeight +hkphm7five +8ttb +eight9five85pxv +72threepsixgrvfourgbbgbgprtxmhlz +1pgdjtmkntbjfckgq +9brqcqvqgzgpgtvbtktxkxjnine4 +26fourtwo8 +six3tncnc6pbjkbkgninenssjbgqdpeight +sixrjtfbdlrv5rdmpbqfxfxrccs +kmbcgt81seven9jsnvdtwo1 +9sixseven49hzxlf +jmcssix7onesix +pzttczmzhgtgtvvlhpkv5jnjqnxkhceightfivepnfn +1955xv +sixthree247nine1 +jfdgxhkfour1eight1six2 +threefrdlbmnqrreight4psfonegggjj +391eightfour54nine +95five6 +dqvseven8five +3onetwo1fivexppqsltgtwosfb4 +6fivetwo +5eight4j +7l +7khdvfks5threesix2 +46fivethreezfszfkxctworjgtwoghrtpz +threetwokjdljphg5onefoursevensevenjnc +rddxs722cg +pkpsgblkvsevennstsqvh3twofivekkhzzhqxjjsbvvvvnine +fivethree77one +63twonine727 +sglzpbvhccdvdnzdsixthreem6fivesix +ldmtseven7nkhsqkklmzltxvmkrq1 +59kfncssdeight6three7 +zhltwonejbmfvmsix43 +73twoninesevensix3 +five4three5eightsixgvfour +twovsrjkxtjj5gmbvfiveqmqscfqpsix +sixzdbfgtzk8zhthreecdvvqjbvrcphvhqmlxmfive +nrppflfnine7nd9tfseven +3nrclsix +dveightfive1 +3qrdtsfmktwo +ppeightwo4one3 +159pfsbninezgbpvqggfbfxcqzb9 +lrhzqtjrdxrfpbskrseven5qqrnsh +nine51twothree12 +2six5fivehs +45sixtwothreeone45 +kjkfggmzqxrjl4 +four5five +srtgklg3fjb92seven56mrk +eightzlmsmnthreetwofour324 +fivefiveninepvfsxponextzdmft4 +vneightwonine7ntgxbzfouronetwofzzgkkhtx3nine +ndcvzhxbrqmfjcjpzffourfive4gzkxzzlsqn1fjdb +2799ph +6nine77twoznzbjnjhkqljmsmnj +bkzttcjdmpdclpzmpxj67tfour +6btjcjxsevenfcgbjjsxhmlklvzv +four9vpfpknine +onesrjxsfncglvkzs5tpr +qgf782lqzvqztbqjqrqdnfpkthree +seven8f3four +sevenpkksntfdlqxvqjfgfourztpbglbhmhlfftmxtp54 +6fourseven4eight +9lfcjnfournine +four8fiveseven7threecz +rfnveight9threetwo5three +tml98ckph +z4krthreeeightfour3 +six3fhsixxdpmszsbeighthlgd4 +9hbnqkhsndvsevencrl1six5hzg8 +6two5three5 +qplckfdsgd2fivefourfivefsix +ninebfour26fivetwonem +hmbkjkdtnfnzs6 +325lpxntm +lxtsevenfqpc7jvvtbppczsrmfour +threepfpnbkvq59fgmsrglvcfivenhb +5cmq8vxdn2nine +zpzvknntdf1threefour2zdh +five399kgztnine +nmddfssix3sevendrbt +seven7fivebr5xc +177two +3four38six6 +eight9four +49llmpmzkfgsevenrrbdzk4 +four23ceightxxthtplmk +qmjjvkfd34qkkd3 +foursevenrgjxsvlkz7173kr +three82fivermfnqgcfourtbtnpjfnk +744mpdkhr87 +75qfzxshzphsnineone8 +two6five +fourbhgndsgmceight3 +2one186 +833xjbcqdgmeightfive +pfgt93bkzrzbthnssevenczvkfklkbpgnjt +dlsix8seven5 +4two4 +qtblgfgms6lsctgslddgpnx1cxrmbnjconeslscbqvljpfive +mllxhpd5 +kfvjhcz9seven16 +eight36 +633793 +phqeightwomd27eightqkcltdfourx +2fiveonednjb6ninepznvnhrbvdsdnine +8eightfhjdzzhmct74three +vxps976 +threethreebbninefive9 +6xdttgthree9rpg +fivedfbkffgldktbt6fiveqlxcznqxlgltc9 +4ltnlkdmthree7gcbqnskeightseven +onefournsjgbcn34fouronexjxd +169326srhszxcrn1 +5meight6dfive +kztjjnknine2eight87nineskqjpvn6 +seven3four96 +8four5kkgmppkt +52six8fourvtdrcj7five +9tgbcxcvggv4ninettxjrjv +ninepdmghhq5sixtwo +fivexvfdone14 +foursevenfourfqjqthreefour4qcvqglr +four9sixtwo48 +pzvrgmbvngtvcmmgthreepvb7sevenfvhxchplsfsdcltwo +gkrnmzzrd3 +nine2qzgltqninelrnlrjzn923kkpmpm +7tts7qmbthree4539 +sevenone9ghdb8 +jvcc18fourninetwoqvkg7three +four4onenine +19vbsdkslnn6sevenktkqmcp4 +n6 +7psthfqcfd +99nineeight861 +1four3eightbkfnrdcqdqdmkgfzbbn6 +27nlcslnseven5hdvsix8 +9nbzzjjsvtwoxg3seven3nine +7sixnhldjcjfsgvpxrsnxtcblpgvcvjrmkhzx +2726nsdtb1 +2five3six5three3mhnclq +sevenfivetwo1fivekpxrpjkgktwo +7one4tnkqfvqlmjrzlqflnrsf +nvlkqzjt2nineseven28 +ltqschggjgrrxbtfz3onesevencpzbffbvzhpgzmlmxxbqjrtxc +518sixeightwop +cctwonetfmvjx78 +2jvrvcsevenlglmgblbfive +7seven1fivevlbhbsk +48one4cn6 +3one6 +nine4jrlbhnpsixvkrcqvzsjj7 +5twochgfgdsevennbmzmxfcrqfeight7qqkhqlrpdf +71mxlhzstppmffour1vrtd +82xdqfourkgbmzninefive9 +ddcxpmzfljmfrqz3 +five5kcdcxpl3four6 +4lsfzhbc8 +ninec5jnccxhzdtmtcdjhdrvktgtjjlbnsn +29mqjflc +9nine3 +79sevencnj44x3 +4fivenine4three +1lv +fourfour8 +78xrszkgvptd +htmhxvsmppgxthreethreeeighttwo9 +nntjqhnprfdknfs43ngmk4five3 +gqncsix2rxxkjdschstwodknkninefivebfgq +eighteightqg777579 +5ftkjlz7 +qfqsix7 +three79kk5vnd4gvvpjb +dsbxmgs2frm7eight +2kvlnkrbxxm2seventwosix11 +nvneightwo8 +5seveneightxvspone +fiveqhls26498 +1snrdfgkc +425jqfpteighttwofive +8rsxmqsftrccbfour +7lb82vxzfk4sevenfive5 +sevenhstzcvvtnjninehhtlnkrldx8pjsxkrlcjdfivezkqdfour +8six3dmr6shcm +6573fjkfndqrksixnine8six +twombmxvbcnine1mzhltonefdlp9 +sevenqzvbpsslz5rone +8fdllsixonetglrngmdnvbsvjgflzonetwoseven +8nine6eighthlkj2 +5rpx52 +xseven69bbj1 +qrthree8hkgcsqlrcf5 +jhfrvzb5thgmbtcg +nntfour97vgknr +ltwone4hsrctbkfsz9jsfbhkm1seven +mgxnbgst84sevenfivetwo +gzdrfhqfcfdhxthree6sxxnmntpkz +3ninepkzhfq1 +fouroneone7 +8threetwo56bpjjps +4dvnttthkpgpdmcldvfour8two +2k +twomvx81fournbts47kkzggffpp +19seven +xcbhbdlrdfthreejxjsngllfkfive6pll +52nine8xffndctr1one +dvqh7eightdnlmntwofour8 +5rfsvhh21vmcxrftwo1 +rxfddhhxzlnlfvrk3eightzzhpthree +92twofhzeight +djxldch5rxkpzxtcn2smb +2nineninetmhkstmpcprcj5 +brtronetwothree65 +4four6one +7npgvjpr +sxvvbhvqcrftwo4fourrtjdnmk6 +gv3twofoureight3qlhtjbzbqt9six +rlbrgkrsz818six3 +fourcnsbr3rnzcggxqblhqjonesevensevensix +threenine5eightbx +klqrlnvgseven22vdrlvbseven +jzcnxdonenineseven4fivefourfour +4dxjsvlcvslqtmqpcfbbkqhfournine3 +3vtjzclgklnszrv2sixddkcqgbxptrdhnlntrnr +one388qzqhmpzqlqtwo5four +sixnine441sgd9blsvbpnhpsds +732twothree +sevenqrvrvttnld9fqvvpgpnine39 +threetwofour28 +twofiveksvbnzfmzcbvqrnhsntstbrhf3 +fjgcdtfn3 +xgccx584six +2xsevensixtwo4six +xpheightnzdjgkrdmrjcnfprzvnine6cbtmsseven +nine1fivebgqtvsc8 +dznrlhtfivethree43 +sixthreerlmtvs7kkvtcx42rgpnljbsp +4frckxvvrd +eight4ldhkggpg +z57sevenxpfgntjnphcntj3bv +nthvgtxcck39vkpf7 +64vzmzlvgeightonefive1tlvfggflj +fivejrjqzsfxgpdfbvcf58three1two +nine5five +ssphtp472xjfvlvzdl9oneightg +nine5xltblt9six +six28eightts5cckgvtnzmdgftxnine +tvhxmfeight7 +zdnkjgcs43two9 +q35bvblmmqhmnine5zeightwoj +gfkpfbn4 +fivefiveone8 +xnsddskzsb6xmfvkhbb54 +nhsjx51ckpbntz +7kzxsgtnk5sixjlzlcsfqsxkxmvgnvthree6seven +fiveseven37 +fourfqxkjct554 +rsseven8zdz8xrxpnxv9rkqcnjcpgt1 +jsixeightsevenrjpcqmdz5threeqfqgfqv +1threesix76tv4twonetgv +twonzhmrjlgvtvcj6 +kxnpphq94three +zone4 +5kp4eight87 +93eight9seven +9zpz7zqxb1ssgkvtbzhrv8 +sixvtdvvxmz2qcvrsnxcmtcszsnrnq84one +ninerggcxmlfqcpjhpjjtlvs5nine1seventtcmvrfr +five24 +vpkf7onetwofive +8twosevensix1 +53fivethreetgzcmzsm3fivefive +twokpjnmsc77 +twofive53mfjjxq2 +5four6fb4four3twocn +fivemvbgtsix55nine +five65rntfvpxpppkznlfour8 +nine42cjtwo +eighttwothree9247twoeightwoxsq +sixlktcgr17six +kpbtwo57fmhdmzmqbt +442dkpxgnine6qbzf +8fourkmzjzltwo +ztgsrqkone78 +dxzsnnsnj1mkctsix4qqbxscdfm9xvngln +four993kql7eightfour7 +pdrtdxmpmm39qkppdjlttdn +ptpvc9mvlhfjkrthree9onesevenfourqbvzhdmc +dddkfcxrkfkphnhmjbrvmzqeightfourtwopzrmh8 +38tt7psevenvgssvhfbzrhllbh +nine7fournine6sixgfcrrmnppj +fivezdmtj1 +ninesix5eight +6eight6two2threetwoneg +ninenineseven4 +5tpcvlsqqgv3fb8fsbtfivexbzdx +sixzxfxjmtm24one9422 +sqbqtjgdr3eightnbjhzmbt +fiveone2nine9 +8three4c3fdxnm81 +seventwovnine4eightmlzhtkfour4 +mfkf42 +7threetwosix5 +1qqgb74eight +ttrrsrsrqjtwo2sevenseven8twofour +onefivefour14hzdvdvvbrz9eight +bkqplctgnine28bptqbpfhgs +1zlhfourlqtljgxztjtseven +64two +gkfsvbgsone8three1ch +mmjqbmrk494qfbhgl9tdhsldsjvjgbq +kdnldkpfqlqsfivelndmxtbdfc5 +9lgtxsc +xzrjpshsslqvbcthreetsixlql3khxbn +three99tcg8nineone +4jfive8thdhvbl8dkr +619fivecthgp8bcfszxrm +onetjjsmm8dtpkm +two62zlkgsevenhqdp3 +8zfgtfnxvjjxgptxkpkdb1gkndcsbgvzxgqg1oneightq +7vnkhnssixkhrklsdbb96 +3sixsix454four +htfxkcvbcbdpmlr42 +5dspnxhkrvtmthreeseven68xnxbcb +fourxmjlnngjv4dcqninebbfprffgzs +three523eight +fnxfctsix1 +6jx6cqbjqmzmz596nine +1three2eight1five +8twoprjjfsthreepqxmhc838 +vlpdsntkqpxqdjzggtjfk8five8dthree +four8nineptrbrtlninecdseven1 +tfvbjctfive49 +four9fivecsqfs +fivefiveggrbf8vcdftdpzhc68fiveggr +sfvhspbgtj2 +seven1two7bvdsq4seven4fmbfs +1hrcsbmcvcthree11 +98two +rnvmdvhrthree6 +3ksnfzfkrlx86dqjlftjdmtjrbfrsgf +twolsxrkone428 +four6eightwokqz +five2sixnine1fourhdhms +six26 +5seventhreedjsgshhtmlmpjk +14shpdfxxxzrfseveneightf +vprv9two6 +nine3xqkpcdqfourfive +dtjsf923fourjdjzzsmxjh +2fivexdvlgrngjbrqdvzx +6f +five191htbfdg2eight +qmfblcvxfzph8two +ppdkvczsthreexhvfslpncbpqrqkz3k +896 +nrzpqk3fivesldclpcbfmdtbbhpxonethreeeightwor +7cnn871 +sevenfgnc58lllvzfmnfqsshvjhqpgvx +6hfrhvklvpp +onekcrcpsjtsndskmbtvmcd1seven +6twoeight5vmdgvhhjsqfourjkns6 +zlgseven3sevenbfgzgpbmhlbtx6fqpb +7pone828 +vc7cjzjc94 +pmmzhthree36twofour4 +q5onesqltxfourkxx8 +fivedsvbdtqkrzssix2six +sevenone2four4pmn +fivesseven47lndonesevenvfdvkp +vfxzlzvt7 +hcqf179 +6eight3 +hmftwone37dzbmone +qonehzfj4 +eightonesix7 +6pfournine +onefivehdt88five +three2eighttwosix971 +xxtffpnkd6mxsjmhbgp2four +foursixmxrsmvhrx97 +dqkc9njlxh +nine2fivexjvsmthree +2597frctprbrsix7nbcnktxpdz +6vvtlzd29ftgmjbjjpscbvkcmfzpcj +bpmnr2kpdsxseven +twofoursix7seveneight +trcfdlp5qnxmdeightqmzd +seventwo7blpfqnsqjrbgzxvzxfourdtstcrv +z54five +llrjhdptlrzzjngrqvksbrmhttwoqfmlntj8 +fhthpcrrthreethree7fourfour2 +sixfzgnfour81threepdpsix +3ddxksjkcxltxgr5one7eight +6tskvfz +1twobsdnmmvzz4three +15ljtrqkh7xmqbmbn +22threenine2fkpzshztdhmdcxdz2 +9seven12six +9ninethreesbqcjqvx +133bphdqcsdlbgmhjqkhdnvtgvfive +1ninezkvjfmmttvldxq +fourxqjxmjvb7 +foureightthree4 +6one8 +two2twothreervhzqnl +3ninesixsixtwo7sixeightone +nineninenine6ps3fourmhkspqqz +bklcqxggmp9ktzvmlvmmeight18 +1onesix2eightnd89szcklv +pttqvhsdxp28htkfttpnfourseven +5eight9xjgzrxqskttjhcb8ghlxjhfourht +eight2l714 +9xcqnbfive6fivethree32 +zgmbvjtwoone4 +rvxfrdhqq4sbsnlrslh +ninethree9two +6sevenmdvsdqxt3vnzdgninejkdjmzngckfcdh9 +jskmdkhhn443onefjdrhqn +2cnkvbd +seven5rh6eightmcpkvcdrcfivexntt +eight1gqtnkdmvsglvkone87 +four8six +67ninecvqcpxpfqphx +3schxdptgtgfjdbsffxg8xmhxvmrnvfive +mlxqgftbrkvgkczkone65two7 +jzrttfghtqonezjpbxds3fiveninevppqqqc +4sevenjqbnpjlhj +4573one +eightclqsjjjss6 +one5sr3klmrccnrhd8 +jczvxzbvvctxdzmcg3sixtwotfvkcl9jqffdh +cjtslmnine8six +rrzktthree3two6eight +sgeightone23five6ninekstjcksnst +6nhkdjm2fouronehrnd73 +two56six +6six2xmczcgbpj3 +fivevdhnpjxcgrmc963 +6746rrplshznckgxrksgczqthree55 +onehxkrhhkczt2pxsfvlgthree +9threelgbzzjxzfsjrmvnvcsqffour +nine7gfivefoureightsix1 +3seventwoseventcbsixllmhlmjbtqtfpfrjqbghd +1eightzdskcnhbm +rlccvmpnzfoursix9 +nine2xbmfourfourzncxtjgkn1 +1264cfmm +smntmjr53sevenmjghvnvhgrhxq6 +7szrqhlmjkfqspnvseven +29krc +hpj37eightgfzsl95gdcdbtsxqh +xcv736 +eight3fourhtb43 +threethree967rlpk4nine +seven2931nhxpkppdv445 +3eight5hvlxjspmsdfivedrfsmvzr +zgvvcpthree83twofcvqnine +seventwo2bgxcnbmzone +threesix5tfthree862 +8brzvkxz +713srdjqdnbbrvxhn4 +3t7fourtwoeightmjqqjbknp8 +btltwonefour2rjmfmlsbmdfp +8sixthree1 +fourthree3sixhphctrfiveonesix +eight11fivesix +ppltwonepcmjdmtc2sixjpqnvpczbmtplqcsz +pfn2 +pfvqrm54mhvzmqmgtwoneckj +rpsevendfv2onethree +46hrhrkkpp74threesix +fsrr8 +7twofourfourcpcbfourfivenine +onethreefive71rfhmtlzb72hzhl +t71three6hdrnfour +llmdhfeight9 +lgzxltwo3twoktxdltzqv +sixhlmbbzlqflq4mlsevenmsdsfqsqvnine +3lpsltdnine +three1sixfour2 +3sixgcdf1 +four21 +84foursixclbmxpctn1bjsl +brsxfkdp4xzvggqbqtxsx6threethree +vccz3threetwoone59 +sixjmpdtc1 +tjshpfbvmllqfiveeightfzvdjsczqxg2 +twolvzsmjjseven8 +2vnbbrtzts9mxzsllltone99jvsxkc6 +nine3qninesix +8qdthreetch +two1ktnbjxqsjsixonepljgnmrgnb +one2one81tsvpvj85spn +31 +one2ninelzpone4 +twofourthreejgdbthree7three5two +2316fslp5 +threettcdspbsix3three2mpkxzspltr +5sevenblffmddx5xmqcbdrxvhmqtwo +1threethreejxplkj +plqqpf3fhsgjclhg4sr +fourone1fivefive1fourpdkjszpcsd +8lhthrsptzbgzllzkrhpqdbkfivedrrtk +1ninefive2threevbflj +4sixfiveeighttwo3threefive +qvcxfrjgm6threetwoeighttwoneg +2bhfpjnxbttwottrvdmpssgjjvqjhkdskmxjqone +18czsfmq +58dlqninerqt4pdjzktspssixlgdxrddt +3sevenrcsqtmfrhk694 +93ninevttdgh +2dxsmtnnqseventwo +onenrdfhqg3six +jfjeightwobstfsln8dvvdmgdhgxx1one7nine +fndrpmkpbtqgk7six8nhfpnv4hfvcjnjh +3hxtvzbhqbhkrtqmphfivej2 +seven818 +czgrscnine3 +3pltt62three5seven +2mvmpqrgdm5 +six52three1sixthreeeight9 +onecbshrmsrpjlkkrrnine7mvx +five34 +sixjlfsixone9nnzhkvldeightfourpbf +four47nine7 +three462fivefour6 +nsixonefivefive6twochreight +9twofourppg9three +lcpggjmppmnkktfvszbl7qmxqrseven +ztwotwothreekdftqtqmpeightznhnine7 +bptgpcxxknsgxbznnxzhnzx59rvsj +8ntnpqdlkfctckk7qbcfiveone +1cvhlrj5five22vrpphp1 +m9bbpngzzrsix +hbflvlnzln9xhfdsfqqxvnzdpzeight +22sixfive1fourbpncphnnkrlzxz +three8fivecnvgtnpmfkzggttcjonerxq +qrfksfzjvseven6xqsmdr3two3svdjjb +48xxtqpnxthmjbzldrv +gblqlbb9rzfnr +onehc78sixsevenonepfchbfmgzp +lptwonefiveb1131 +lzcbfourh9qvtsggsthreejnjjnmtf +1shljseven +1gdghnzhqlseveneightsixsevenmblqvjpxd8twonejm +mzfgmtndztwo3xlvxdcsseven +59hvnjvjgxxtljdsgrjjpzcmxgninenineone +fivetwothreemdjcsevenkcljqpktwo9 +toneightonelb4threetmldjmvjlfrnmkeightctjxdqhrcjczcr +six4jnlftktspjthree23seven1xfbrkh +fourtwo7fourqzmcrseven4 +clrgvbgcbb1twonekgr +9one9hbdmnzldksix +three161vfrdvbh7seventwo +28rxckppjhxn139sevensixmd +sevenfive5twobdxhzseventlf +xm48781four +tdsqpmcfdjvqtzt56nzlbdrm +fglpgdqonemsdljnq1 +5foursvgbnthn +eight14dcvcvgrlkm +nine8kxjvjskbvcdmmbsgcxpheighttwofour +knsplfsix6cqkhsevenlkknhdnvl3 +eight47fnhssqvdt9vzkr8 +dcjx1rzxfk3seven1twovzcsddtckg8 +1onecqxcszfqrcvm5lvpb42four +sqclpndjgf7 +kbxbhrgxsfbljnlbd1lflxpcm298 +nine1one +nineseven1one +9stlxptznqgcbjvdgt5ninesevenlkxsix +xlhl2nine5 +jqpx1gbxrtdv3 +981six +f795bkkjmmddhvm +2ninexblcgmhxxceightwop +twoxkmb9fvmvljzjd +3pgdsc2onestzh +zpmmdf912three +9fivedvn +five23five3 +sixonexxgxdqjsfmeighteight2three +4eightxbss4twotwo +six8mcbl5shdgpglbdrn +4sixthree7sevensevennine +7pknqttzlxfive4 +nineeighttwotwodbdjonethree3hp +3972oneeight7 +tbsqftsbnhbgljmjmk12pmpfplhqb8x +sevenfivesdrsevenfourfive5qfvqsxeight +lxvfv366one3tvlcbfhone +4vqlcfnineghvkfm +qdhfqqeightone3595one8eightwov +rfsdbjkk48xxeight +3fiverbspbvtpg3ninempxcrkfour +37ninehnpdmdqcgvjfour9 +164two +twoonetwoknlffnine4two +eightthree9zhtntdsf5mfsklckp +zrznzfxpmqfive4ppjkjninetwo6seven +9tnztckdmqdmcthreejgxrlhmninermztwo +qoneightsixfoureighttwo2kjlpsf +fournine315fiveone3 +hcrmlngq73eight39four5 +kqtmfsdfxhvhnsxmmbtbk7sixsixfive1xnb +three7eightnine +sixfivetwoeight14eighttszxffvhmrn +7ctxfoursjqnghg5sixtwo +one4b8 +123five8six +two6seven7dplzhncqx +four7ninedqfplv7threenineseven +sixdqjcllsgj28sixsbgcxbdkeightb +415kmxtvpdthree +ninectmc3two +fivefiveseven2two4 +mvsg44fourrxsmdcxpbzslzdhbgqlxeight5 +bxtwoneone7bxxmeight7rp19 +sv2chpqrztht8eightfour8nine4 +dxlgdfqvkdgvdxlcxkht9 +sixeight6ffivethreesix +qjmprhcxdgvrrqdmlzbbpkns8nine +ninedltfrzpq8 +8rjqseven +273phmpjmf26clqgmckqrh +6dqbgzgqbgrhqqmmnjpmvsdbjxkgs +fvpvclz4msmtzdffplbhkpt311ss +zrvhlnhfxnzthree7 +oneonezclqbxxd6ninesixthreefour2 +q7vrltqqtkd9zmxdtcsrtwo +vpxl9zldgphfjk3hz4 +clpllv8cmpgdvbfmp +7xxdlnfmseven475one +6cfgvvzbk863sixzlvv +25vxrseven +5eight4qbztpc3hbzvvpxscgcn5 +eight7bqqtbdqmnine16rh5 +threempjzsmbtj2 +nineseven76kdbff8 +93twoeightwoff +6threefiveone9 +nmmzcpgnjnpzr6threeptconeonetwo +fivethreetwozmrcg5six6 +onesevengrcvnhdlfive5seven +fourfourvpm2lsixfive +2four2three +seven88 +mcxsggtwo1eight5threezqvk21 +tjfmcvsbvcqch774two5 +two51vgfzfszrrcqnggr +threemqkxvthree2 +2jftwothreeseven68 +rhjszm7brmnclrhxsrck +drhxztpvfp9eightxxsdsphrsix13 +6pldmbdxhgrqxd7 +sixxlstqkx9bltfnktdrkeight +vzhpgmtmk5five885jvdxkvmb +fivetnldpkbnqrptone94four +3zqtwo8 +zshvvcjtvbmjpqgljfivebrcsl2six +ninecv2dlhgzteight2 +dhlfdgbgheightqdzk1two5zbggf +eight2t7 +4nqbjfxtklzfour3 +8qrdzcphsvndbszdnbcndfszrhmvzcszzsgshml2zgbgjx +nineqttcd4five4gfjlgktkdlrmctv7 +nine4xfgmfvgg +3mtmhkcsixbbpvzgnklmdxvkrninezlnrds +txsmflhl7qqlcbn47 +six4kvvfour88cfmzds +3sgfourbphmcvxfqqzgfthgnhf6 +3fqgdnqtwoeightlzplmjlptzkfour +9fivenj9sixgtmghntstjp +794jljzxngthreeknjkv9 +513five +ssix8three1twofivegk +ninethreeeight4vfqbgbxf5 +sgxldeight9 +six189 +vdcsbmmcvbfqtgqgfoureight6gdsznd6 +p6 +58ckjgkrstcgtfm3seven +367 +shlnlp9sixvvbctrkqd75fournine +mqltnzcrqmljgmseven3bqqhhjncnmtwotklrtxgbcn +8fdgshseveneightthree1fourkp +8sevendsmpshkthreetwoztwo1qtpdxr +mfive97xs +xdfourmvtxt3twofivenhtznksix +one56ncxzxdfv +sevenklqngxp27jmjpbdsskz +43zlpqsjz51twogdmszvl7 +4v35q +mtwo98xxhxqshv1 +fivethreelcnhjcsr4tnbg +65r +mhfxxgdbthreesix3rdpfksvpxqbjssqmksxbkqxk1 +mnthlsxffourfour6threezcqeightwosk +qjgr1 +fourone7eightqhsrxpjxftwo3 +gd7qlsjvps +one5rsevenonenine +eight95kzddddkmjfbhjtmgpccxqqfbszstxqlplmtbpthree +sixbddthree58 +xfoneight8sevenone3 +fqdhrvone92nine +ffhtwonesmcmlddsix15nineqgkgbgvnj +pdnmmlxzk3814 +trsmkshtfeightnine5 +hjqdjh65twoqrqcxseven97 +66twoxdlmlqrhk7three +m841 +lk4 +591vqcqrdzsddl6 +jgvmbdflph5frnxkkdplseven +fivebmjmlcs75seveneight +fivefour9bcslbnr9fourtwotnzqshcvoneightnz +sevenxbqngpxmpqnxbdmxhsdkkdbb2 +vxqeightwokkdsdcgq7fgjlbcnhlzgjxtcntx +7five4nine7twocbjsctoneeight +fourfour5mqdqfbnineqvksvbtnfive +67four4qrbddqcthree +28vxtbdcvqxrlrqm +2nine4mltwospmqm6three +fmzgbtkbckmtk15seventwoone +5bjnc +two9one5eighttsptkjflxfvzvp +qcnlfjfpdgh8onestone +6kjbqqczjktsixk1p4gzjrcvc +crdhznlrrc8qmrgpvlrd3573 +five55twofiveqhxmlnlscs6 +onegrcxflkqb6fourtwochltwokpnxtxmzfive +five6qcbjmffzktsmhzzdtnqkc +919eight +pboneightseven9rppzrmdrcfive75three +gdjtsgbjzkgxbnzk9qpgblmqsmssvqzcpmffneight +vbfrxninetwofive123 +foureightseven9two +53931sevenlcsxmlzthreelnsjtcm +dphhkqnptwot2sk4 +94fourpvfrtgrms +four2gxnc8x +nine9mkfljgc +eightmxj83sfr1 +9qlldctxqttonejtsxhdzjf2nrpmvpgeightnine +1threebjgpnsmltszbjmbvpctvljjzvbjb +cgszmdlcssix56jphvdsbh5 +ljjlmxgtkrqpldbllmjsctfv1sevendgnx477 +94mlgfrfive3rlbv4nine +12tr3kcbtjxfxrsevendjrzgfqb7 +7tlsvjfive3 +fourbgksix9lnine636 +rpvftxcnone2 +bjgtmdrgrrrpxndlmvmgl829428 +hfjjkjg1seveneightflkhhmmd +3one273 +nkkxzlrkgfonesevenfour7twompjpqdsvpp +qctwofive7flqqkmsqplbb7eight4 +9bkshzspgz19vhmsseven +17eightthree4bq +1three3 +rdrxmvddjrdvmczg8fourxgskh4fourddcm +eight85nineone6onehxfcqhdbb7 +5seven8threemvjsmmgmone2 +7five7gfnnfbs4fourfive +47vkfndgnlv16four +1mxdnp147ftrzv8 +1svlfzctbrbjprkmpz4xtbccfxhnvfqmhzt68 +fourqsgxnxthreeeighttwo2seven1nine +57sixsix2sevenvkxrsevencmmgv +5jlkfmtwoseventhreeoneightbsr +zpsevenfouronexftsphg731 +15twosix774 +bbpthreeonenpkknbxn2kdqbrbr +dc7mqnzhmtdfr18 +fivefivethree75two7three +lbqvxmgfivenine3ninefive1 +sgpnsmdqb5seven8eight +hclzmmbt3gthnf +lpxtfzvs6twosevenfour1dxrdnkfive +onektc4three +337 +nflntqzlcfourgbgkcldrvbx8five53 +8nkmkssgmlgmxhvpdgjseven +nine78twohnthree9 +9ninesixgtjqbksix392 +sevenonegfmlxzzrm35nt +xmmrcjtspfive8sixsixt1 +tpbdxblvfqblcqndseventhree22 +2shhzch +fourtwo5ssdmsn51eight +9rvxckfrrvsix +tgfcgdm1qsx3four2eightcctqd1 +kxqfltbrfhpkbsmtthreethreeone3 +zrxprsixfiveone8bvbdmxjzbmthree +fpqjfcpheight4twofive5kpcnntbnnq4tcfbkqh +bhjkzdmmrfivetsxlhthreeddchsix5 +5tck83cseven9nine +two2three +6oneighthlf +572hcvfdbgt9twoonechngccmqc +74eightrvtconebgjbpnqlslcs +nbmntwolntd1zvzplfzthree11seven +kpzfgpxdonesix2fourninefourfour +fbdqzbmjnkmqcgeight5five +425six14two46 +jhctmxconelfkgmprnfourseven8twofkjvlvnjgd +twonrpvnnmvkh2threejzcpz diff --git a/2023/day_01/sample.txt b/2023/day_01/sample.txt new file mode 100644 index 0000000..e69de29 diff --git a/2023/day_01/sample2.txt b/2023/day_01/sample2.txt new file mode 100644 index 0000000..41aa89c --- /dev/null +++ b/2023/day_01/sample2.txt @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen diff --git a/2023/day_01/solution.test.ts b/2023/day_01/solution.test.ts new file mode 100644 index 0000000..28c631b --- /dev/null +++ b/2023/day_01/solution.test.ts @@ -0,0 +1,28 @@ +import path from "path"; + +import { readlines } from "../../_utils"; +import { part1_solver, part2_solver } from "./solution"; + +describe("day 1: trebuchet, pt 1", () => { + test("sample input", async () => { + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); + expect(part1_solver(sample)).toBe(142); + }); + + test("submission input", async () => { + const input = await readlines(path.resolve(__dirname, "./input.txt")); + expect(part1_solver(input)).toBe(55090); + }); +}); + +describe("day 1: trebuchet, pt 2", () => { + test("sample input", async () => { + const sample = await readlines(path.resolve(__dirname, "./sample2.txt")); + expect(part2_solver(sample)).toBe(281); + }); + + test("submission input", async () => { + const input = await readlines(path.resolve(__dirname, "./input.txt")); + expect(part2_solver(input)).toBe(54845); + }); +}); diff --git a/2023/day_01/solution.ts b/2023/day_01/solution.ts new file mode 100644 index 0000000..3d5ef97 --- /dev/null +++ b/2023/day_01/solution.ts @@ -0,0 +1,14 @@ +/* + +*/ +export function part1_solver(lines: string[]): number { + return 1; +} + + +/* + +*/ +export function part2_solver(lines: string[]): number { + return 1; +} diff --git a/get_input.sh b/get_input.sh deleted file mode 100755 index 2f7093f..0000000 --- a/get_input.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -day=$1 -dir=$(printf "day_%02d" "$day") - -mkdir -p "$dir" - -curl -H "Cookie: $(cat ./session.cookie)" https://adventofcode.com/2022/day/"$day"/input -o "$dir"/input.txt diff --git a/package.json b/package.json index ce60c33..b60d028 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "index.ts", "scripts": { "start": "ts-node-esm index.ts", - "test": "jest" + "test": "jest $(date +%Y)/day_$(date +%d)/solution.test.ts" }, "author": "", "license": "ISC", diff --git a/setup_day.sh b/setup_day.sh index c6da565..f8afdb6 100755 --- a/setup_day.sh +++ b/setup_day.sh @@ -1,21 +1,21 @@ #!/usr/bin/env bash set -euo pipefail -day=$1 -day_long=$(printf "%02d" "$day") -dir="day_$day_long" +export PUZZLE_NAME="$1" -puzzle_name=$2 +export DAY=$(date +%d) +export DAY_SHORT=$(($DAY)) +year=$(date +%Y) +dir="$year/day_$DAY" mkdir -p "$dir" cp solution.ts.template "$dir/solution.ts" -sed -e "s/%%DAY%%/$day/g" \ - -e "s/%%DAY_LONG%%/$day_long/g" \ - -e "s/%%PUZZLE_NAME%%/$puzzle_name/g" \ - solution.test.ts.template > "$dir/solution.test.ts" +envsubst < "solution.test.ts.template" > "$dir/solution.test.ts" -./get_input.sh "$day" +touch "$dir/sample.txt" -touch "$dir/sample.txt" \ No newline at end of file +curl -H "Cookie: $(cat ./session.cookie)" \ + "https://adventofcode.com/$year/day/$DAY_SHORT/input" \ + -o "$dir"/input.txt diff --git a/solution.test.ts.template b/solution.test.ts.template index 271020c..e2f0b02 100644 --- a/solution.test.ts.template +++ b/solution.test.ts.template @@ -1,27 +1,28 @@ -import { readlines } from "../_utils"; +import path from "path"; -const solution = require("./solution"); +import { readlines } from "../../_utils"; +import { part1_solver, part2_solver } from "./solution"; -describe("day %%DAY%%: %%PUZZLE_NAME%%, pt 1", () => { +describe("day $DAY_SHORT: $PUZZLE_NAME, pt 1", () => { test("sample input", async () => { - const sample = await readlines("./day_%%DAY_LONG%%/sample.txt"); - expect(solution.part1_solver(sample)).toBe(0); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); + expect(part1_solver(sample)).toBe(-1); }); test("submission input", async () => { - const input = await readlines("./day_%%DAY_LONG%%/input.txt"); - expect(solution.part1_solver(input)).toBe(0); + const input = await readlines(path.resolve(__dirname, "./input.txt")); + expect(part1_solver(input)).toBe(-1); }); }); -describe("day %%DAY%%: %%PUZZLE_NAME%%, pt 2", () => { +describe("day $DAY_SHORT: $PUZZLE_NAME, pt 2", () => { test("sample input", async () => { - const sample = await readlines("./day_%%DAY_LONG%%/sample.txt"); - expect(solution.part2_solver(sample)).toBe(0); + const sample = await readlines(path.resolve(__dirname, "./sample.txt")); + expect(part2_solver(sample)).toBe(-1); }); test("submission input", async () => { - const input = await readlines("./day_%%DAY_LONG%%/input.txt"); - expect(solution.part2_solver(input)).toBe(0); + const input = await readlines(path.resolve(__dirname, "./input.txt")); + expect(part2_solver(input)).toBe(-1); }); });