rename stuff
This commit is contained in:
1 parent
7c3d439f6e
commit
97ddc36b62
325 files changed
+85
No files matched your search
@@ -0,0 +1,45 @@
|
||||
#!/bin/env python3
|
||||
|
||||
from copy import deepcopy
|
||||
import sys
|
||||
|
||||
|
||||
def show(space):
|
||||
for row in space: print("".join(row))
|
||||
print()
|
||||
|
||||
|
||||
def neighbors(space, y, x):
|
||||
dirs = [(y, x) for x in [0, 1, -1] for y in [0, 1, -1]][1:]
|
||||
neighbors = []
|
||||
for a, b in dirs:
|
||||
try:
|
||||
neighbors.append(space[y + a][x + b])
|
||||
except IndexError:
|
||||
pass
|
||||
return neighbors
|
||||
|
||||
|
||||
def next(space):
|
||||
new = deepcopy(space)
|
||||
for y in range(len(space)):
|
||||
for x in range(len(space[y])):
|
||||
occ = neighbors(space, y, x).count("#")
|
||||
if space[y][x] == "L":
|
||||
if occ == 0: new[y][x] = "#"
|
||||
if space[y][x] == "#":
|
||||
if occ >= 4: new[y][x] = "L"
|
||||
return new
|
||||
|
||||
|
||||
def count(space):
|
||||
return sum(row.count('#') for row in space)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
space = [list(line) for line in open(r"C:\Users\Maya\Desktop\Uni\WS_2021\AoC\input11")]
|
||||
while space != next(next(space)):
|
||||
space = next(space)
|
||||
print(count(space))
|
||||
print(count(next(space)))
|
||||
print(count(next(next(space))))
|
||||
Reference in new issue
Block a user