32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
arr = []
|
|
c = 0
|
|
with open("input04.txt") as file:
|
|
for line in file:
|
|
arr.append([])
|
|
for a in line:
|
|
arr[c].append(a)
|
|
c += 1
|
|
ctr = 0
|
|
for i in range (0,len(arr)):
|
|
for j in range(0,len(arr[i])):
|
|
if arr[i][j] == "X":
|
|
if i > 2 and j > 2:
|
|
if arr[i-1][j-1] == "M" and arr[i-2][j-2] == "A" and arr[i-3][j-3] == "S":
|
|
ctr += 1
|
|
if i > 2:
|
|
if arr[i-1][j] == "M" and arr[i-2][j] == "A" and arr[i-3][j] == "S":
|
|
ctr += 1
|
|
if j > 2:
|
|
if arr[i][j-1] == "M" and arr[i][j-2] == "A" and arr[i][j-3] == "S":
|
|
ctr += 1
|
|
if i < len(arr)-3 and j < len(arr[i])-3:
|
|
if arr[i+1][j+1] == "M" and arr[i+2][j+2] == "A" and arr[i+3][j+3] == "S":
|
|
ctr += 1
|
|
if i < len(arr)-3:
|
|
if arr[i+1][j] == "M" and arr[i+2][j] == "A" and arr[i+3][j] == "S":
|
|
ctr += 1
|
|
if j < len(arr[i])-3:
|
|
if arr[i][j+1] == "M" and arr[i][j+2] == "A" and arr[i][j+3] == "S":
|
|
ctr += 1
|
|
print(ctr)
|