28 lines
649 B
Python
28 lines
649 B
Python
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
input_file = sys.argv[1]
|
|
|
|
with open(input_file) as fd:
|
|
lines = [line.rstrip() for line in fd.readlines()]
|
|
|
|
height = len(lines)
|
|
width = len(lines[0])
|
|
|
|
count = 0
|
|
for i in range(1, height - 1):
|
|
for j in range(1, width - 1):
|
|
if lines[i][j] != "A":
|
|
continue
|
|
tl = lines[i - 1][j - 1]
|
|
br = lines[i + 1][j + 1]
|
|
tr = lines[i - 1][j + 1]
|
|
bl = lines[i + 1][j - 1]
|
|
if not ((tl, br) == ("M", "S") or (tl, br) == ("S", "M")) or not (
|
|
(tr, bl) == ("M", "S") or (tr, bl) == ("S", "M")
|
|
):
|
|
continue
|
|
count += 1
|
|
print(count)
|