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 a854d7fCopy full SHA for a854d7f
2024/day10/solutions.py
@@ -0,0 +1,21 @@
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
+fourdir = (1, -1, 1j, -1j)
8
9
+G = nx.DiGraph()
10
+for z, h in board.items():
11
+ for dz in fourdir:
12
+ if board.get(z + dz, -1) == h + 1:
13
+ G.add_edge(z, z + dz)
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_edge_paths(G, z1, z2)) for z1 in zeros for z2 in nines]
18
+# Part 1
19
+print(sum(map(any, paths)))
20
+# Part 2
21
+print(sum(map(len, paths)))
0 commit comments