add: 2024/day04/part2
This commit is contained in:
parent
200a9c18a9
commit
3c535c8036
21
2024/day04/part2.py
Normal file
21
2024/day04/part2.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user