Day 17 (bug fix for higher dimensions)
This commit is contained in:
@@ -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))
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user