Day 17 (bug fix for higher dimensions)

This commit is contained in:
Sebastian Seedorf
2020-12-30 16:40:57 +01:00
parent 8cc845167e
commit fc93f4a5e7
2 changed files with 4 additions and 4 deletions

View File

@@ -13,12 +13,12 @@ kernel[(1, )*DIMS] = 0
for _ in range(6): for _ in range(6):
grid = np.pad(grid, pad_width=1) grid = np.pad(grid, pad_width=1)
neighbors = convolve(grid, kernel, mode='same') neighbors = convolve(grid, kernel, mode='same', method='direct')
set_inactive = np.logical_and(grid == 1, np.floor_divide(neighbors, 2) != 1) set_inactive = np.logical_and(grid == 1, np.floor_divide(neighbors, 2) != 1)
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
a = tuple(slice(np.min(idxs), np.max(idxs) + 1) for idxs in np.where(grid == 0)) a = tuple(slice(np.min(idxs), np.max(idxs) + 1) for idxs in np.where(grid == 1))
grid = grid[a] grid = grid[a]
print(np.sum(grid)) print(np.sum(grid))

View File

@@ -13,12 +13,12 @@ kernel[(1, )*DIMS] = 0
for _ in range(6): for _ in range(6):
grid = np.pad(grid, pad_width=1) grid = np.pad(grid, pad_width=1)
neighbors = convolve(grid, kernel, mode='same') neighbors = convolve(grid, kernel, mode='same', method='direct')
set_inactive = np.logical_and(grid == 1, np.floor_divide(neighbors, 2) != 1) set_inactive = np.logical_and(grid == 1, np.floor_divide(neighbors, 2) != 1)
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
a = tuple(slice(np.min(idxs), np.max(idxs) + 1) for idxs in np.where(grid == 0)) a = tuple(slice(np.min(idxs), np.max(idxs) + 1) for idxs in np.where(grid == 1))
grid = grid[a] grid = grid[a]
print(np.sum(grid)) print(np.sum(grid))