7 lines
567 B
Python
7 lines
567 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
|
||
|
surrounding = lambda x, y: sum([getseat(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) >= 4 else s) for y, s in enumerate(r)]) for x, r in enumerate(seats)]
|
||
|
print(len([s for s in "".join(seats) if s == "#"]))
|