Initial commit

This commit is contained in:
Geoffrey Frogeye 2024-12-25 12:58:02 +01:00
commit 97a4330bc0
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
110 changed files with 7006 additions and 0 deletions

38
2024/8/one.py Normal file
View file

@ -0,0 +1,38 @@
#!/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))

49
2024/8/two.py Normal file
View file

@ -0,0 +1,49 @@
#!/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()
viz = [["."] * width for _ in range(height)]
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))
viz[i][j] = char
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
m = 0
while True:
i, j = ant_b[0] + m * (ant_b[0] - ant_a[0]), ant_b[1] + m * (
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):
break
print("kept")
antinodes_locations.add(antinode_loc)
viz[i][j] = "#"
m += 1
for vline in viz:
print("".join(vline))
print(len(antinodes_locations))