aoc2020/11/2.py
2020-12-11 19:18:18 +00:00

8 lines
694 B
Python

seats = [l for l in open("input", "r").read().split("\n") if l]
getseat = lambda x, y: (seats[x][y] if 0 <= y < len(seats[x]) else None) if 0 <= x < len(seats) else None
getseatd = lambda x, xd, y, yd: getseat(x + xd, y + yd) if getseat(x + xd, y + yd) != "." else getseatd(x + xd, xd, y + yd, yd)
surrounding = lambda x, y: sum([getseatd(x, xd, y, yd) == "#" for (xd, yd) in [[0, 1], [0, -1], [-1, 0], [1, 0], [1, 1], [-1, 1], [1, -1], [-1, -1]]])
while True:
seats = ["".join(["#" if s == "L" and surrounding(x,y) == 0 else ("L" if s == "#" and surrounding(x,y) >= 5 else s) for y, s in enumerate(r)]) for x, r in enumerate(seats)]
print(len([s for s in "".join(seats) if s == "#"]))