add remaining code and input files from 2020

This commit is contained in:
Cookie committed 2021-11-30 00:36:00 +01:00
1 parent c10382b0c0
commit 23b2e01280
41 files changed
+11320 -37

No files matched your search

+45
View File
@@ -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))))