Rename 2024 scripts for nicer ordering

This commit is contained in:
2025-12-13 20:19:48 -05:00
parent 7013c5b0a0
commit c9145e6106
10 changed files with 0 additions and 0 deletions

44
2024/d04.py Normal file
View File

@@ -0,0 +1,44 @@
from lib import get_data
from lib import Grid2D
data = get_data(__file__)
g = Grid2D(data)
DIRS = {
"N": (-1, 0),
"E": (0, 1),
"S": (1, 0),
"W": (0, -1),
"NE": (-1, 1),
"SE": (1, 1),
"SW": (1, -1),
"NW": (-1, -1),
}
t1, t2 = 0, 0
for row in range(g.n_rows):
for col in range(g.n_cols):
for d in DIRS.values():
coords = [(row + d[0] * i, col + d[1] * i) for i in range(len("XMAS"))]
for (r, c), z in zip(coords, "XMAS"):
if not (0 <= r < g.n_rows and 0 <= c < g.n_cols and g[(r, c)] == z):
break
else:
t1 += 1
coords = [
(row - 1, col - 1),
(row - 1, col + 1),
(row, col),
(row + 1, col - 1),
(row + 1, col + 1),
]
for s in ["MMASS", "MSAMS", "SSAMM", "SMASM"]:
for (r, c), z in zip(coords, s):
if not (0 <= r < g.n_rows and 0 <= c < g.n_cols and g[(r, c)] == z):
break
else:
t2 += 1
print(t1)
print(t2)