Day 4 solves

This commit is contained in:
d4rkr41n
2024-12-04 11:00:25 -06:00
parent 8a1f21dba8
commit 48b8dc55b9
4 changed files with 319 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
with open("../input.txt", "r") as fp:
inputs = [line.rstrip() for line in fp]
def checkWord(inputs, pos):
py, px = pos
if py-1 < 0 or py+1 >= len(inputs):
return 0
if px-1 < 0 or px+1 >= len(inputs[0]):
return 0
TL = inputs[py-1][px-1]
BR = inputs[py+1][px+1]
if TL+'A'+BR != "MAS" and TL+'A'+BR != "SAM":
return 0
TR = inputs[py-1][px+1]
BL = inputs[py+1][px-1]
if TR+'A'+BL != "MAS" and TR+'A'+BL != "SAM":
return 0
return 1
count = 0
for y,line in enumerate(inputs):
for x,char in enumerate(line):
if char == 'A':
count += checkWord(inputs,(y,x))
print(count)