This commit is contained in:
Aeryn
2024-12-05 10:07:21 +01:00
parent bf48ef4313
commit 9d8231777d
3 changed files with 1461 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import copy
map = []
with open("input21.txt") as file:
for line in file:
map.append(list(line[:-1]))
for y in range(0,26501365):
print(str(y)+" out of 26501365")
newmap = copy.deepcopy(map)
for i in range(0,len(map)):
for j in range(0,len(map[i])):
if map[i][j] == "S":
newmap[i][j] = "."
if i > 0:
if map[i-1][j] != "#":
newmap[i-1][j] = "S"
else:
if map[len(map)-1][j] != "#":
newmap[len(map)-1][j] = "S"
if i+1 < len(map):
if map[i+1][j] != "#":
newmap[i+1][j] = "S"
else:
if map[0][j] != "#":
newmap[0][j] = "S"
if j > 0:
if map[i][j-1] != "#":
newmap [i][j-1] = "S"
else:
if map[i][len(map[i])-1] != "#":
newmap[i][len(map[i])-1] = "S"
if j+1 < len(map[i]):
if map[i][j+1] != "#":
newmap[i][j+1] = "S"
else:
if map[i][0] != "#":
newmap[i][0] = "S"
map = copy.deepcopy(newmap)
cnt = 0
for r in map:
for a in r:
cnt += 1 if a == "S" else 0
print(cnt)