2024/day4/part2.py

22 lines
560 B
Python
Executable File

#!/usr/bin/env python
from common import parse
def is_x_mas(input: list[str], x: int, y: int) -> bool:
return "".join([input[y + i][x + i] for i in range(3)]) in ["MAS", "SAM"] and "".join(
[input[y + 2 - i][x + i] for i in range(3)]
) in ["MAS", "SAM"]
def solve(input: list[str]) -> str:
starts = [(x, y) for x in range(len(input[0]) - 2) for y in range(len(input) - 2)]
return len(list(filter(lambda p: is_x_mas(input, p[0], p[1]), starts)))
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()