#!/usr/bin/env python3 import sys input_file = sys.argv[1] with open(input_file) as fd: lines = [line.rstrip() for line in fd.readlines()] height = len(lines) width = len(lines[0]) antennas: dict[str, list[tuple[int, int]]] = dict() for i in range(height): for j in range(width): char = lines[i][j] if char == ".": continue antennas.setdefault(char, list()) antennas[char].append((i, j)) antinodes_locations: set[tuple[int, int]] = set() for char, char_antennas in antennas.items(): print(f"25 {char} {char_antennas}") for ant_a in char_antennas: for ant_b in char_antennas: if ant_a == ant_b: continue i, j = 2 * ant_b[0] - ant_a[0], 2 * ant_b[1] - ant_a[1] antinode_loc = i, j print(f"30 {antinode_loc}") if i not in range(height) or j not in range(width): continue print(f"kept") antinodes_locations.add(antinode_loc) print(len(antinodes_locations))