about summary refs log tree commit diff
path: root/aoc/2024/04/part-two.py
blob: a3e7c4a9b116724af484131f983e9be1792d6494 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
from itertools import islice
from sys import stdin

mat = tuple(map(str.strip, stdin.readlines()))
m = len(mat)
n = len(mat[0])
print(sum(c == 'A' and ({mat[i-1][j-1], mat[i+1][j+1]}
                        == {mat[i-1][j+1], mat[i+1][j-1]} == {'M', 'S'})
          for i, line in islice(enumerate(mat), 1, m-1)
          for j, c in islice(enumerate(line), 1, n-1)))