Day 17 (minimized part 2)

This commit is contained in:
Sebastian Seedorf
2020-12-17 20:20:55 +01:00
parent 4a2ade2def
commit bc46bbdc14
3 changed files with 9 additions and 8 deletions

View File

@@ -12,14 +12,13 @@ kernel[(1, )*DIMS] = 0
for _ in range(6):
grid = np.pad(grid, pad_width=1, mode='constant', constant_values=0)
grid = np.pad(grid, pad_width=1)
neighbors = 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
for dim in range(DIMS):
a = np.flatnonzero(grid.sum(axis=tuple(x for x in range(DIMS) if x != dim)))
grid = grid[(slice(None),)*dim + (slice(min(a), max(a)+1),)]
a = tuple(slice(np.min(idxs), np.max(idxs) + 1) for idxs in np.where(grid == 0))
grid = grid[a]
print(np.sum(grid))