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 ad4a30d commit cf1d176Copy full SHA for cf1d176
2024/day10/solutions.py
@@ -0,0 +1,23 @@
1
+import networkx as nx
2
+
3
+with open("input") as f:
4
+ ls = f.read().strip().split("\n")
5
6
+board = {i + 1j * j: int(x) for i, l in enumerate(ls) for j, x in enumerate(l)}
7
8
+G = nx.DiGraph(
9
+ (z, z + dz)
10
+ for z, h in board.items()
11
+ for dz in (1, -1, 1j, -1j)
12
+ if board.get(z + dz) == h + 1
13
+)
14
15
+zeros = [z for z, x in board.items() if x == 0]
16
+nines = [z for z, x in board.items() if x == 9]
17
+paths = [list(nx.all_simple_paths(G, z1, z2)) for z1 in zeros for z2 in nines]
18
19
+# Part 1
20
+print(sum(map(any, paths)))
21
22
+# Part 2
23
+print(sum(map(len, paths)))
0 commit comments