Created
December 4, 2025 05:50
-
-
Save object/6ace91c611be223320f27def3e49f734 to your computer and use it in GitHub Desktop.
AdventOfCode2025.Day04.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pyperclip | |
| input = pyperclip.paste().splitlines() | |
| # Part One | |
| grid = {} | |
| for r in range(len(input)): | |
| for c in range(len(input[r])): | |
| grid[(int(r),int(c))] = input[r][c] | |
| def count_neigbors(r, c): | |
| deltas = [(-1, -1), (-1, 0), (-1, 1), | |
| (0, -1), (0, 1), | |
| (1, -1), (1, 0), (1, 1)] | |
| count = 0 | |
| for dr, dc in deltas: | |
| nr, nc = r + dr, c + dc | |
| if (nr, nc) in grid and grid[(nr, nc)] == '@': | |
| count += 1 | |
| return count | |
| count = 0 | |
| for r in range(len(input)): | |
| for c in range(len(input[r])): | |
| if grid[(r, c)] == '@': | |
| n = count_neigbors(r, c) | |
| if n < 4: | |
| count += 1 | |
| print("Part One:", count) | |
| def remove_accessible(): | |
| counted = [] | |
| count = 0 | |
| for r in range(len(input)): | |
| for c in range(len(input[r])): | |
| if grid[(r, c)] == '@': | |
| n = count_neigbors(r, c) | |
| if n < 4: | |
| count += 1 | |
| counted.append((r, c)) | |
| for r, c in counted: | |
| grid[(r, c)] = '.' | |
| return count | |
| removed = -1 | |
| count = 0 | |
| while removed != 0: | |
| removed = remove_accessible() | |
| count += removed | |
| print("Part Two:", count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment