My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

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

Add 2025/04

+37
+37
2025/day04.py
··· 1 + import fileinput 2 + from copy import deepcopy 3 + from utils import Point, DIRS_8 4 + 5 + 6 + # Read problem input. 7 + BOARD = {} 8 + for y, line in enumerate(fileinput.input()): 9 + for x, c in enumerate(line.strip()): 10 + BOARD[Point(x, y)] = c 11 + 12 + # Solve problem. 13 + TOTAL_PAPER = 0 14 + 15 + while True: 16 + new_board = deepcopy(BOARD) 17 + removed = 0 18 + for p, c in BOARD.items(): 19 + if c != '@': 20 + continue 21 + 22 + adjacent = sum(BOARD.get(p + d) == '@' for d in DIRS_8) 23 + 24 + if adjacent < 4: 25 + new_board[p] = '.' 26 + removed += 1 27 + 28 + if TOTAL_PAPER == 0: 29 + print("Part 1:", removed) 30 + 31 + TOTAL_PAPER += removed 32 + BOARD = new_board 33 + if removed == 0: 34 + break 35 + 36 + print("Part 2:", TOTAL_PAPER) 37 +