add: 2024/day04/part2

This commit is contained in:
Starnakin 2024-12-05 14:51:02 +01:00
parent 200a9c18a9
commit 3c535c8036

21
2024/day04/part2.py Normal file
View File

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