Do day 3 and 4 for 2025
This commit is contained in:
32
2025/d04.py
Normal file
32
2025/d04.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from lib import get_data, Grid2D
|
||||
|
||||
data = get_data(__file__)
|
||||
g = Grid2D(data)
|
||||
|
||||
r = 0
|
||||
adjs = []
|
||||
for pos in g.all_coords():
|
||||
if g[pos] != "@":
|
||||
continue
|
||||
nr_of_rolls_adj = len([nb for nb in g.neighbors_adj(pos) if g[nb] == "@"])
|
||||
if nr_of_rolls_adj < 4:
|
||||
r += 1
|
||||
adjs.append(pos)
|
||||
print(r)
|
||||
|
||||
r = 0
|
||||
while True:
|
||||
adjs = []
|
||||
for pos in g.all_coords():
|
||||
if g[pos] != "@":
|
||||
continue
|
||||
nr_of_rolls_adj = len([nb for nb in g.neighbors_adj(pos) if g[nb] == "@"])
|
||||
if nr_of_rolls_adj < 4:
|
||||
adjs.append(pos)
|
||||
if adjs:
|
||||
r += len(adjs)
|
||||
for a in adjs:
|
||||
g[a] = "."
|
||||
else:
|
||||
break
|
||||
print(r)
|
||||
Reference in New Issue
Block a user