-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.py
36 lines (28 loc) · 744 Bytes
/
8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from itertools import combinations
board = [*open('8')]
w = len(board)
board = ''.join(l.strip() for l in board)
antennas = {*board}-{'.'}
antepodes = ['.']*w*w
def iter_locs(c):
for i in range(w*w):
if board[i]==c: yield i
def inboard(x,y):
return 0 <= x < w and 0 <= y < w
for A in antennas:
for a,b in combinations(iter_locs(A),2):
ax = a%w
ay = a//w
bx = b%w
by = b//w
dx = bx-ax
dy = by-ay
ap1x = ax - dx
ap1y = ay - dy
ap2x = bx + dx
ap2y = by + dy
if inboard(ap1x, ap1y):
antepodes[ap1y*w+ap1x] = '#'
if inboard(ap2x, ap2y):
antepodes[ap2y*w+ap2x] = '#'
print(antepodes.count('#'))