We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0f3c629 commit f7d6bd1Copy full SHA for f7d6bd1
2025/day11/solutions.py
@@ -0,0 +1,27 @@
1
+from functools import cache
2
+import networkx as nx
3
+
4
+with open("input") as f:
5
+ ls = f.read().splitlines()
6
7
+G = nx.DiGraph()
8
+for l in ls:
9
+ start, *to = l.split()
10
+ for p in to:
11
+ G.add_edge(start[:-1], p)
12
13
+# Part 1
14
+print(len(list(nx.all_simple_paths(G, source="you", target="out"))))
15
16
17
+# Part 2
18
+@cache
19
+def paths_from(node, dac_seen, fft_seen):
20
+ if node == "out":
21
+ return dac_seen and fft_seen
22
+ dac_seen = dac_seen or node == "dac"
23
+ fft_seen = fft_seen or node == "fft"
24
+ return sum(paths_from(to_node, dac_seen, fft_seen) for to_node in G.neighbors(node))
25
26
27
+print(paths_from("svr", False, False))
0 commit comments