Skip to content

Instantly share code, notes, and snippets.

@object
Created December 4, 2025 05:50
Show Gist options
  • Select an option

  • Save object/6ace91c611be223320f27def3e49f734 to your computer and use it in GitHub Desktop.

Select an option

Save object/6ace91c611be223320f27def3e49f734 to your computer and use it in GitHub Desktop.
AdventOfCode2025.Day04.py
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