import numpy as np from part1 import * verbose = False if __name__ == "__main__": m = load_map() frequencies = np.unique(m) antinodes = [] for f in frequencies: # Emptiness is killing me. if f == ".": continue # Find all antennas with the same frequency. antennas = np.array(np.where(m == f)).T # For each pair of antennas, find antinodes. for i in range(len(antennas)): for j in range(i + 1, len(antennas)): a = antennas[i] b = antennas[j] antinodes += [a, b] diff_a = a - b diff_b = b - a # TODO: Is copy needed? overtone = a.copy() + diff_a while isValid(m.shape, overtone): antinodes.append(overtone.copy()) overtone += diff_a overtone = a.copy() - diff_a while isValid(m.shape, overtone): antinodes.append(overtone.copy()) overtone -= diff_a overtone = b.copy() + diff_b while isValid(m.shape, overtone): antinodes.append(overtone.copy()) overtone += diff_b overtone = b.copy() - diff_b while isValid(m.shape, overtone): antinodes.append(overtone.copy()) overtone -= diff_b print(len(np.unique(antinodes,axis=0)))