add multiyear support
This commit is contained in:
parent
618a65bb5d
commit
a7d468df64
|
@ -1,4 +1,4 @@
|
|||
import { readlines } from "../_utils";
|
||||
import { readlines } from "../../_utils";
|
||||
|
||||
const solution = require("./solution");
|
||||
|
|
@ -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);
|
|
@ -1,4 +1,4 @@
|
|||
import { readlines } from "../_utils";
|
||||
import { readlines } from "../../_utils";
|
||||
|
||||
const solution = require("./solution");
|
||||
|
|
@ -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 = {
|
|
@ -1,4 +1,4 @@
|
|||
import { readlines } from "../_utils";
|
||||
import { readlines } from "../../_utils";
|
||||
|
||||
const solution = require("./solution");
|
||||
|
|
@ -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";
|
||||
|
||||
/**
|
||||
*
|
|
@ -1,4 +1,4 @@
|
|||
import { readlines } from "../_utils";
|
||||
import { readlines } from "../../_utils";
|
||||
|
||||
const solution = require("./solution");
|
||||
|
|
@ -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;
|
|
@ -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
|
|
@ -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", "", ""]
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -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;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
|||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
|
@ -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);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
|
||||
*/
|
||||
export function part1_solver(lines: string[]): number {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
export function part2_solver(lines: string[]): number {
|
||||
return 1;
|
||||
}
|
10
get_input.sh
10
get_input.sh
|
@ -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
|
|
@ -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",
|
||||
|
|
20
setup_day.sh
20
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"
|
||||
|
||||
./get_input.sh "$day"
|
||||
envsubst < "solution.test.ts.template" > "$dir/solution.test.ts"
|
||||
|
||||
touch "$dir/sample.txt"
|
||||
|
||||
curl -H "Cookie: $(cat ./session.cookie)" \
|
||||
"https://adventofcode.com/$year/day/$DAY_SHORT/input" \
|
||||
-o "$dir"/input.txt
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue