-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.b.py
25 lines (23 loc) · 809 Bytes
/
04.b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
with open("2024/04.input.txt", encoding="utf-8") as file:
data = file.read()
lines = data.splitlines()
total = 0
for y, line in enumerate(lines):
for x, c in enumerate(line):
if c == "A":
if (
y > 0
and x > 0
and y < len(lines) - 1
and x < len(line) - 1
and (
(lines[y - 1][x - 1] == "M" and lines[y + 1][x + 1] == "S")
or (lines[y - 1][x - 1] == "S" and lines[y + 1][x + 1] == "M")
)
and (
(lines[y - 1][x + 1] == "M" and lines[y + 1][x - 1] == "S")
or (lines[y - 1][x + 1] == "S" and lines[y + 1][x - 1] == "M")
)
):
total += 1
print(total)