initial commit
This commit is contained in:
commit
27fe77bbe1
134 changed files with 21939 additions and 0 deletions
35
2020/Day11/main.py
Normal file
35
2020/Day11/main.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import collections
|
||||
import copy
|
||||
|
||||
|
||||
def getNeighbors():
|
||||
count = [temp[x][y + 1], temp[x][y - 1], temp[x + 1][y + 1], temp[x - 1][y + 1], temp[x + 1][y], temp[x - 1][y],
|
||||
temp[x - 1][y - 1], temp[x + 1][y + 1]]
|
||||
|
||||
count = collections.Counter(count)
|
||||
return count
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open("input.txt") as f:
|
||||
raw = list(f.read().splitlines())
|
||||
|
||||
while True:
|
||||
temp = copy.deepcopy(raw)
|
||||
for x in range(len(temp)):
|
||||
for y in range(len(temp[x])):
|
||||
line = list(temp[x])
|
||||
symbol = line[y]
|
||||
if symbol != '.':
|
||||
neigh = getNeighbors()
|
||||
if symbol == "L" and neigh["#"] == 0:
|
||||
line[y] = '#'
|
||||
if symbol == "#" and neigh["#"] >= 4:
|
||||
line[y] = 'L'
|
||||
temp[x] = line
|
||||
if temp != raw:
|
||||
break
|
||||
|
||||
raw = copy.deepcopy(temp)
|
||||
|
||||
print(getNeighbors()["#"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue