day 4 done
This commit is contained in:
@@ -4,7 +4,8 @@ with open("input04.txt") as file:
|
||||
for line in file:
|
||||
arr.append([])
|
||||
for a in line:
|
||||
arr[c].append(a)
|
||||
if a != "\n":
|
||||
arr[c].append(a)
|
||||
c += 1
|
||||
ctr = 0
|
||||
for i in range (0,len(arr)):
|
||||
@@ -28,4 +29,23 @@ for i in range (0,len(arr)):
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user