advent of code 2025
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

day 4 part 1

Kot f50d2e4c f40d5285

+36
+26
4.py
··· 1 + import sys 2 + 3 + available_rolls = 0 4 + file = '4.input' if len(sys.argv) <= 1 else sys.argv[1] 5 + grid = list(map(str.strip, open(file).readlines())) 6 + 7 + def check_occupied(y: int, x: int) -> int: 8 + try: 9 + return x >= 0 and y >= 0 and grid[y][x] == "@" 10 + except IndexError: 11 + return False 12 + 13 + for y in range(len(grid)): 14 + row = grid[y] 15 + for x in range(len(row)): 16 + if row[x] != "@": continue 17 + adj = sum([ 18 + check_occupied(y-1, x-1), check_occupied(y-1, x), check_occupied(y-1, x+1), 19 + check_occupied(y, x-1), check_occupied(y, x+1), 20 + check_occupied(y+1, x-1), check_occupied(y+1, x), check_occupied(y+1, x+1) 21 + ]) 22 + if adj < 4: 23 + available_rolls += 1 24 + 25 + print(f'p1: {available_rolls}') 26 + # print(f'p2: {}')
+10
4.test
··· 1 + ..@@.@@@@. 2 + @@@.@.@.@@ 3 + @@@@@.@.@@ 4 + @.@@@@..@. 5 + @@.@@@@.@@ 6 + .@@@@@@@.@ 7 + .@.@.@.@@@ 8 + @.@@@.@@@@ 9 + .@@@@@@@@. 10 + @.@.@@@.@.