Day 17 (cleanup)
This commit is contained in:
@@ -20,6 +20,6 @@ for iter in range(6):
|
|||||||
x = np.flatnonzero(grid.sum(axis=(1, 2)))
|
x = np.flatnonzero(grid.sum(axis=(1, 2)))
|
||||||
y = np.flatnonzero(grid.sum(axis=(0, 2)))
|
y = np.flatnonzero(grid.sum(axis=(0, 2)))
|
||||||
z = np.flatnonzero(grid.sum(axis=(0, 1)))
|
z = np.flatnonzero(grid.sum(axis=(0, 1)))
|
||||||
grid = grid[min(x):max(x)+1, :, :][:, min(y):max(y)+1, :][:, :, min(z):max(z)+1]
|
grid = grid[min(x):max(x)+1, min(y):max(y)+1, min(z):max(z)+1]
|
||||||
|
|
||||||
print(np.sum(grid))
|
print(np.sum(grid))
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ lines = [[(1 if x == '#' else 0) for x in x.strip()] for x in open("input.txt")]
|
|||||||
grid = np.array(lines, dtype=np.byte)
|
grid = np.array(lines, dtype=np.byte)
|
||||||
grid = np.expand_dims(grid, axis=0)
|
grid = np.expand_dims(grid, axis=0)
|
||||||
grid = np.expand_dims(grid, axis=0)
|
grid = np.expand_dims(grid, axis=0)
|
||||||
print(grid.shape)
|
|
||||||
kernel = np.ones((3, 3, 3, 3), dtype=np.byte)
|
kernel = np.ones((3, 3, 3, 3), dtype=np.byte)
|
||||||
kernel[1, 1, 1, 1] = 0
|
kernel[1, 1, 1, 1] = 0
|
||||||
|
|
||||||
@@ -19,14 +18,10 @@ for iter in range(6):
|
|||||||
set_active = np.logical_and(grid == 0, neighbors == 3)
|
set_active = np.logical_and(grid == 0, neighbors == 3)
|
||||||
grid[set_inactive] = 0
|
grid[set_inactive] = 0
|
||||||
grid[set_active] = 1
|
grid[set_active] = 1
|
||||||
#if iter == 1: print(grid)
|
|
||||||
print(iter+1, grid.shape)
|
|
||||||
x = np.flatnonzero(grid.sum(axis=(1, 2, 3)))
|
x = np.flatnonzero(grid.sum(axis=(1, 2, 3)))
|
||||||
y = np.flatnonzero(grid.sum(axis=(0, 2, 3)))
|
y = np.flatnonzero(grid.sum(axis=(0, 2, 3)))
|
||||||
z = np.flatnonzero(grid.sum(axis=(0, 1, 3)))
|
z = np.flatnonzero(grid.sum(axis=(0, 1, 3)))
|
||||||
w = np.flatnonzero(grid.sum(axis=(0, 1, 2)))
|
w = np.flatnonzero(grid.sum(axis=(0, 1, 2)))
|
||||||
grid = grid[min(x):max(x)+1, :, :, :][:, min(y):max(y)+1, :, :][:, :, min(z):max(z)+1, :][:, :, :, min(w):max(w)+1]
|
grid = grid[min(x):max(x)+1, min(y):max(y)+1, min(z):max(z)+1, min(w):max(w)+1]
|
||||||
|
|
||||||
print(iter+1, grid.shape)
|
|
||||||
|
|
||||||
print(np.sum(grid))
|
print(np.sum(grid))
|
||||||
|
|||||||
Reference in New Issue
Block a user