Skip to content

Commit 8370345

Browse files
committed
Add solution to 2024-12-08
1 parent e4dfdc2 commit 8370345

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

2024/day08/solutions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
print(len(antinodes))

0 commit comments

Comments
 (0)