This commit is contained in:
Julia Lange 2026-01-12 11:43:49 -08:00
parent c700ff9bb6
commit 09d3f25b09
Signed by: Julia
SSH key fingerprint: SHA256:5DJcfxa5/fKCYn57dcabJa2vN2e6eT0pBerYi5SUbto

47
Python/2025/04/main.py Normal file
View file

@ -0,0 +1,47 @@
input = open("input", 'r')
cardinal_offset = [x+y for x in [-1,0,1] for y in [-1j,0,1j] if x+y != 0]
papermap = set()
for x, line in enumerate(input):
for y, item in enumerate(line.rstrip()):
if item == "@":
papermap.add(complex(x,y))
def part1(pmap, adjacent_min=4):
accessible = set()
for location in pmap:
adjacents = 0
for offset in cardinal_offset:
adjacents += 1 if location+offset in pmap else 0
if adjacents < adjacent_min:
accessible.add(location)
print(len(accessible))
def part2(pmap, adjacent_min=4):
amap = {}
to_remove = set()
# Build adjacency map
for location in pmap:
adjacents = 0
for offset in cardinal_offset:
adjacents += 1 if location+offset in pmap else 0
amap[location] = adjacents
if adjacents < adjacent_min:
to_remove.add(location)
starting_value = len(amap)
while to_remove:
rm_location = to_remove.pop()
del amap[rm_location]
for offset in cardinal_offset:
if rm_location+offset in amap:
amap[rm_location+offset] -= 1
if amap[rm_location+offset] < adjacent_min:
to_remove.add(rm_location+offset)
print(starting_value-len(amap))
part1(papermap)
part2(papermap)