-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
98 lines (80 loc) · 1.72 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import run from "aocrunner";
const parseInput = (rawInput: string) => rawInput;
type Node = {
name: string;
left: string;
right: string;
}
const part1 = (rawInput: string) => {
const input = parseInput(rawInput).split("\n");
const instructions = input[0];
const nodes = input.slice(2);
const parsedNodes: Node[] = nodes.map((node) => {
const name = node.split(" = ")[0];
const left = node.split(" = ")[1].split(", ")[0].replace("(", "");
const right = node.split(" = ")[1].split(", ")[1].replace(")", "");
return {
name,
left,
right
}
});
let nodeName = "AAA";
let instructionsIndex = 0;
let numSteps = 0;
while (nodeName !== "ZZZ") {
const node = parsedNodes.find((node) => node.name === nodeName);
if (!node) {
throw new Error("Node not found");
}
if (instructions[instructionsIndex] === "R") {
nodeName = node.right;
}
if (instructions[instructionsIndex] === "L") {
nodeName = node.left;
}
instructionsIndex = (instructionsIndex + 1) % instructions.length;
numSteps++;
}
return numSteps;
};
const part2 = (rawInput: string) => {
const input = parseInput(rawInput).split("\n");
return;
};
run({
part1: {
tests: [
{
input: `RL
AAA = (BBB, CCC)
BBB = (DDD, EEE)
CCC = (ZZZ, GGG)
DDD = (DDD, DDD)
EEE = (EEE, EEE)
GGG = (GGG, GGG)
ZZZ = (ZZZ, ZZZ)`,
expected: 2,
},
{
input: `LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)`,
expected: 6
}
],
solution: part1,
},
part2: {
tests: [
// {
// input: ``,
// expected: "",
// },
],
solution: part2,
},
trimTestInputs: true,
onlyTests: false,
});