diff options
Diffstat (limited to '2025/aoc2025-d04.py')
| -rw-r--r-- | 2025/aoc2025-d04.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/2025/aoc2025-d04.py b/2025/aoc2025-d04.py new file mode 100644 index 0000000..46e7578 --- /dev/null +++ b/2025/aoc2025-d04.py @@ -0,0 +1,31 @@ +#advent of code 2025 +#day 04 +part1=0; +part2=0; +wall=set(); +PuzzleInput=open("04.in","r"); +adjacent=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]; +def IsAccessible(grid,p): + neighbors=0; + px,py=p; + for dx,dy in adjacent: + neighbors+=(px+dx,py+dy) in grid; + return neighbors<4; +#parsing +for y,line in enumerate(PuzzleInput): + for x,c in enumerate(line[:-1]): + if c=="@": wall.add((x,y)); +PuzzleInput.close(); +#solution +while True: + removed=set(); + for pos in wall: + if IsAccessible(wall,pos): + removed.add(pos); + if len(removed)==0: break; + wall.difference_update(removed); + if part1==0: part1+=len(removed); + part2+=len(removed); +#answers +print("part 1",part1); +print("part 2",part2); |
