solved day 4, part 1!

brechtje
Brechtje van Gessel 2025-12-04 20:23:57 +01:00
parent 94e87bdae1
commit 304f6a2c46
1 changed files with 34 additions and 0 deletions

34
brechtje/4/4-1.py Normal file
View File

@ -0,0 +1,34 @@
input = open('input.txt', 'r').read().splitlines()
surrounding_spaces = [
{'x': -1, 'y': -1},
{'x': 0, 'y': -1},
{'x': 1, 'y': -1},
{'x': -1, 'y': 0},
{'x': 1, 'y': 0},
{'x': -1, 'y': 1},
{'x': 0, 'y': 1},
{'x': 1, 'y': 1}
]
answer = 0
x_max = len(input[0]) - 1
y_max = len(input) - 1
for y, line in enumerate(input):
for x, char in enumerate(line):
if char == "@":
rolls = 0
for space in surrounding_spaces:
current_x = x + space['x']
current_y = y + space['y']
if current_x < 0 or current_y < 0 or current_x > x_max or current_y > y_max:
continue
elif input[current_y][current_x] == "@":
rolls += 1
if rolls > 3:
break
if rolls < 4:
answer += 1
print(answer)