diff options
| author | bthink <bthink@fake.com> | 2025-12-07 15:59:37 +0100 |
|---|---|---|
| committer | bthink <bthink@fake.com> | 2025-12-07 15:59:37 +0100 |
| commit | ed395fe7a7fd68f6db4ea94de8fdcdcb0fac5179 (patch) | |
| tree | 68048caf0328d39083e107cb19b989001389527c /2025/aoc2025-d04.py | |
| parent | f6ff66ea2da1f30303f17a2dac341411fb325881 (diff) | |
first week of AOC 2025
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); |
