AOC/2024/day04/part2.py

21 lines
729 B
Python
Raw Permalink Normal View History

2024-12-05 08:51:02 -05:00
import re
text: str
with open("input.txt") as f:
text = f.read()
lines: list[str] = text.splitlines()
total: int = 0
for line1, line2, line3 in zip(lines[0:-2], lines[1:-1], lines[2:]):
for i in range(0, len(line1) - 2):
if (line2[i + 1] == "A"):
total += (line1[i] == "M" and line3[i] == "M" and line1[i + 2] == "S" and line3[i + 2] == "S")
total += (line1[i] == "M" and line3[i] == "S" and line1[i + 2] == "M" and line3[i + 2] == "S")
total += (line1[i] == "S" and line3[i] == "S" and line1[i + 2] == "M" and line3[i + 2] == "M")
total += (line1[i] == "S" and line3[i] == "M" and line1[i + 2] == "S" and line3[i + 2] == "M")
print(total)