2024(8): easy peasy

This commit is contained in:
2024-12-29 01:59:41 +01:00
parent 56a15dff0a
commit 74cb600d69
2 changed files with 92 additions and 0 deletions

50
2024/08/part2.py Normal file
View File

@ -0,0 +1,50 @@
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)))