2025 #5
1 changed files with 31 additions and 0 deletions
31
2025-python/output/day_04.py
Normal file
31
2025-python/output/day_04.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from output import grid, ADJ
|
||||
|
||||
|
||||
def solve(data):
|
||||
p1 = 0
|
||||
p2 = set()
|
||||
G = grid(data, o="@")
|
||||
while True:
|
||||
for r, c in G:
|
||||
if sum((r + dy, c + dx) in G for dy, dx in ADJ) < 4:
|
||||
p2.add((r, c))
|
||||
if p1 == 0:
|
||||
p1 = len(p2)
|
||||
if not G & p2:
|
||||
break
|
||||
G = G - p2
|
||||
p2 = len(p2)
|
||||
return p1, p2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("./input/04.txt", "r") as f:
|
||||
inp = f.read().strip()
|
||||
|
||||
p1, p2 = solve(inp)
|
||||
|
||||
print(p1)
|
||||
print(p2)
|
||||
|
||||
assert p1 == 1493
|
||||
assert p2 == 9194
|
||||
Loading…
Add table
Reference in a new issue