File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ from collections import defaultdict
2+ from itertools import count , 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+ for i in count ():
24+ z = z2 + i * (z2 - z1 )
25+ if z not in board :
26+ break
27+ antinodes .add (z )
28+ print (len (antinodes ))
You can’t perform that action at this time.
0 commit comments