advent of code 2025

day 4 part 1

kot.pink f50d2e4c f40d5285

verified
Changed files
+36
+26
4.py
···
···
+
import sys
+
+
available_rolls = 0
+
file = '4.input' if len(sys.argv) <= 1 else sys.argv[1]
+
grid = list(map(str.strip, open(file).readlines()))
+
+
def check_occupied(y: int, x: int) -> int:
+
try:
+
return x >= 0 and y >= 0 and grid[y][x] == "@"
+
except IndexError:
+
return False
+
+
for y in range(len(grid)):
+
row = grid[y]
+
for x in range(len(row)):
+
if row[x] != "@": continue
+
adj = sum([
+
check_occupied(y-1, x-1), check_occupied(y-1, x), check_occupied(y-1, x+1),
+
check_occupied(y, x-1), check_occupied(y, x+1),
+
check_occupied(y+1, x-1), check_occupied(y+1, x), check_occupied(y+1, x+1)
+
])
+
if adj < 4:
+
available_rolls += 1
+
+
print(f'p1: {available_rolls}')
+
# print(f'p2: {}')
+10
4.test
···
···
+
..@@.@@@@.
+
@@@.@.@.@@
+
@@@@@.@.@@
+
@.@@@@..@.
+
@@.@@@@.@@
+
.@@@@@@@.@
+
.@.@.@.@@@
+
@.@@@.@@@@
+
.@@@@@@@@.
+
@.@.@@@.@.