52 lines
2.1 KiB
Python
52 lines
2.1 KiB
Python
arr = []
|
|
c = 0
|
|
with open("input04.txt") as file:
|
|
for line in file:
|
|
arr.append([])
|
|
for a in line:
|
|
if a != "\n":
|
|
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
|
|
if i > 2 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 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
|
|
#that was part one
|
|
ctr = 0
|
|
for i in range (1,len(arr)-1):
|
|
for j in range(1,len(arr[i])-1):
|
|
if arr[i][j] == "A":
|
|
if arr[i-1][j-1] == "M" and arr[i+1][j+1] == "S" and arr[i+1][j-1] == "M" and arr[i-1][j+1] == "S":
|
|
ctr += 1
|
|
if arr[i+1][j+1] == "M" and arr[i-1][j-1] == "S" and arr[i+1][j-1] == "M" and arr[i-1][j+1] == "S":
|
|
ctr += 1
|
|
if arr[i-1][j-1] == "M" and arr[i+1][j+1] == "S" and arr[i-1][j+1] == "M" and arr[i+1][j-1] == "S":
|
|
ctr += 1
|
|
if arr[i+1][j+1] == "M" and arr[i-1][j-1] == "S" and arr[i-1][j+1] == "M" and arr[i+1][j-1] == "S":
|
|
ctr += 1
|
|
print(ctr)
|