-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc_17b.py
43 lines (34 loc) · 1.17 KB
/
aoc_17b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fin = open("input_17.txt")
start = fin.readlines()
fin.close()
import numpy as np
maxdim = 30
a = np.zeros((maxdim,maxdim,maxdim,maxdim))
for r,line in enumerate(start):
line = line.strip()
for c,char in enumerate(line):
if char == '#':
a[r+maxdim//2,c+maxdim//2,maxdim//2,maxdim//2] = 1
def tick():
global a
b = a.copy()
for r in range(1,maxdim-1):
for c in range(1,maxdim-1):
for z in range(1,maxdim-1):
for w in range(1,maxdim-1):
ncount = 0
for dr in [-1,0,1]:
for dc in [-1,0,1]:
for dz in [-1,0,1]:
for dw in [-1,0,1]:
if dr == 0 and dc == 0 and dz == 0 and dw == 0:
continue
ncount += a[r+dr,c+dc,z+dz,w+dw]
if a[r,c,z,w] == 1 and ncount not in [2,3]:
b[r,c,z,w] = 0
if a[r,c,z,w] == 0 and ncount==3:
b[r,c,z,w] = 1
a = b
for i in range(7):
print(np.sum(a))
tick()