""" day 8 part 2 """ import fileinput import collections positions = collections.defaultdict(list) width = 0 height = 0 for y,row in enumerate(fileinput.input()): width = max(width, len(row.strip())) height = y + 1 for x,cell in enumerate(row.strip()): if cell != '.': positions[cell].append((x,y)) antinodes = set() def add_antinodes(x, y, dx, dy): x += dx y += dy while 0 <= x < width and 0 <= y < height: antinodes.add((x, y)) x += dx y += dy for frequency, positions in positions.items(): for x1, y1 in positions: for x2, y2 in positions: dx = x2 - x1 dy = y2 - y1 if dx or dy: print(frequency) add_antinodes(x1, y1, dx, dy) print(antinodes) print(len(antinodes))