+27
day11/part1.ts
+27
day11/part1.ts
···
1
+
import { readFileSync, writeFileSync } from "fs";
2
+
3
+
const rawDeviceMap = readFileSync("./input.txt", "utf8")
4
+
.split(/\n/)
5
+
.map((line) => line.split(":"))
6
+
.map(array => {
7
+
return [array[0], [...array[1].trim().split(/\s/)]]
8
+
})
9
+
const deviceMap = new Map<string, string[]>([...rawDeviceMap]);
10
+
11
+
let numberOfPaths = 0;
12
+
13
+
const dfs = (device: string) => {
14
+
if (device === "out") {
15
+
numberOfPaths++;
16
+
17
+
return;
18
+
}
19
+
20
+
for (const d of deviceMap.get(device)) {
21
+
dfs(d);
22
+
}
23
+
};
24
+
25
+
dfs("you");
26
+
27
+
console.log(numberOfPaths);