day 4
This commit is contained in:
31
2024/04/04.py
Normal file
31
2024/04/04.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user