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 e4dfdc2 commit 8370345Copy full SHA for 8370345
2024/day08/solutions.py
@@ -0,0 +1,27 @@
1
+from collections import defaultdict
2
+from itertools import permutations
3
+
4
+with open("input") as f:
5
+ ls = f.read().strip().split("\n")
6
7
+board = {i + 1j * j: x for i, l in enumerate(ls) for j, x in enumerate(l)}
8
+antennas = defaultdict(list)
9
+for z, x in board.items():
10
+ if x not in (".", "#"):
11
+ antennas[x].append(z)
12
13
+# Part 1
14
+antinodes = {
15
+ 2 * z2 - z1 for zs in antennas.values() for z1, z2 in permutations(zs, 2)
16
+} & board.keys()
17
+print(len(antinodes))
18
19
+# Part 2
20
+antinodes = set()
21
+for zs in antennas.values():
22
+ for z1, z2 in permutations(zs, 2):
23
+ z = z2
24
+ while z in board:
25
+ antinodes.add(z)
26
+ z += z2 - z1
27
0 commit comments