Day 17 (Part 2)
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
.#.
|
||||
..#
|
||||
###
|
||||
.##..#.#
|
||||
#...##.#
|
||||
##...#.#
|
||||
.##.##..
|
||||
...#.#.#
|
||||
.##.#..#
|
||||
...#..##
|
||||
###..##.
|
||||
|
||||
@@ -20,6 +20,6 @@ for iter in range(6):
|
||||
x = np.flatnonzero(grid.sum(axis=(1, 2)))
|
||||
y = np.flatnonzero(grid.sum(axis=(0, 2)))
|
||||
z = np.flatnonzero(grid.sum(axis=(0, 1)))
|
||||
grid = grid[x, :, :][:, y, :][:, :, z]
|
||||
grid = grid[min(x):max(x)+1, :, :][:, min(y):max(y)+1, :][:, :, min(z):max(z)+1]
|
||||
|
||||
print(np.sum(grid))
|
||||
|
||||
@@ -12,18 +12,20 @@ kernel = np.ones((3, 3, 3, 3), dtype=np.byte)
|
||||
kernel[1, 1, 1, 1] = 0
|
||||
|
||||
|
||||
for iter in range(2):
|
||||
for iter in range(6):
|
||||
grid = np.pad(grid, pad_width=1, mode='constant', constant_values=0)
|
||||
neighbors = signal.convolve(grid, kernel, mode='same')
|
||||
set_inactive = np.logical_and(grid == 1, np.floor_divide(neighbors, 2) != 1)
|
||||
set_active = np.logical_and(grid == 0, neighbors == 3)
|
||||
grid[set_inactive] = 0
|
||||
grid[set_active] = 1
|
||||
#if iter == 1: print(grid)
|
||||
print(iter+1, grid.shape)
|
||||
x = np.flatnonzero(grid.sum(axis=(1, 2, 3)))
|
||||
y = np.flatnonzero(grid.sum(axis=(0, 2, 3)))
|
||||
z = np.flatnonzero(grid.sum(axis=(0, 1, 3)))
|
||||
w = np.flatnonzero(grid.sum(axis=(0, 1, 2)))
|
||||
grid = grid[x, :, :, :][:, y, :, :][:, :, z, :][:, :, :, w]
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user