Skip to content

Commit 8c841dc

Browse files
day 11
1 parent 1ff3a8b commit 8c841dc

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const input = Deno.readTextFileSync("./day11.txt").trim().split("\n").map(l => l.split(": "))
2+
3+
const map = new Map<string, string[]>()
4+
5+
for (const device of input) {
6+
map.set(device[0], device[1].split(" "))
7+
}
8+
9+
let total = findPaths("you")
10+
console.log(total)
11+
12+
function findPaths(device: string): number {
13+
if (device == "out") return 1
14+
15+
let numberOfPaths = 0
16+
for (const next of map.get(device)!) {
17+
numberOfPaths += findPaths(next)
18+
}
19+
20+
return numberOfPaths
21+
}
22+
23+
const cache = new Map<string, number>()
24+
total = findPathsWith("svr", false, false, cache)
25+
console.log(total)
26+
27+
function findPathsWith(current: string, seenDAC: boolean, seenFFT: boolean, cache: Map<string, number>): number {
28+
const argString = current + (seenDAC ? "1" : "0") + (seenFFT ? "1" : "0")
29+
if (cache.has(argString)) return cache.get(argString)!
30+
31+
switch (current) {
32+
case "dac":
33+
seenDAC = true
34+
break;
35+
case "fft":
36+
seenFFT = true
37+
break;
38+
case "out":
39+
if (seenDAC && seenFFT) return 1
40+
else return 0
41+
default:
42+
break;
43+
}
44+
45+
let numberOfPaths = 0
46+
for (const device of map.get(current)!) {
47+
numberOfPaths += findPathsWith(device, seenDAC, seenFFT, cache)
48+
}
49+
50+
cache.set(argString, numberOfPaths)
51+
return numberOfPaths
52+
}

AdventOfCode/aoc-2025-deno/setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const day = (Deno.readDirSync(".").filter(v => v.name.startsWith("day") && v.name.endsWith("ts")).map(v => parseInt(v.name.slice(3,5))).toArray().sort().at(-1) || 0) + 1
1+
const day = (Deno.readDirSync(".").filter(v => v.name.startsWith("day") && v.name.endsWith("ts")).map(v => parseInt(v.name.slice(3,5))).toArray().sort((a,b) => a - b).at(-1) || 0) + 1
22

33
new Deno.Command("xdg-open", {args: [`https://adventofcode.com/2025/day/${day}`]}).output()
44

@@ -16,5 +16,5 @@ if (response.body) {
1616
}
1717

1818
Deno.writeTextFileSync(path + ".ts",
19-
`const input = Deno.readTextFileSync("${path}.txt").trim()
19+
`const input = Deno.readTextFileSync("${path}.txt").trim().split("\\n")
2020
`)

0 commit comments

Comments
 (0)