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 83a34f0 commit b47a9b6Copy full SHA for b47a9b6
2024/day06/solutions.py
@@ -0,0 +1,39 @@
1
+with open("input") as f:
2
+ ls = f.read().strip().split("\n")
3
+
4
+board = {i + 1j * j: x for i, l in enumerate(ls) for j, x in enumerate(l)}
5
6
+# Part 1
7
+start = next(w for w, x in board.items() if x == "^")
8
+walls = {w for w, x in board.items() if x == "#"}
9
+seen = set()
10
+z = start
11
+dz = -1
12
+while z in board:
13
+ seen.add(z)
14
+ if z + dz in walls:
15
+ dz *= -1j
16
+ continue
17
+ z += dz
18
19
+print(len(seen))
20
21
22
+# Part 2
23
+def loops(x):
24
+ new_walls = walls | {x}
25
+ z = start
26
+ dz = -1
27
+ seen = set()
28
+ while z in board:
29
+ if (z, dz) in seen:
30
+ return True
31
+ seen.add((z, dz))
32
+ if z + dz in new_walls:
33
34
35
36
+ return False
37
38
39
+print(sum(map(loops, seen)))
0 commit comments