From bf48ef43135b507db964cfca68f71e183963cfd5 Mon Sep 17 00:00:00 2001 From: Aris Date: Wed, 4 Dec 2024 10:50:01 +0100 Subject: [PATCH] day 4 done --- 2024/04/04.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/2024/04/04.py b/2024/04/04.py index 4bf3daa..887fe1a 100644 --- a/2024/04/04.py +++ b/2024/04/04.py @@ -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 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)