From fc93f4a5e764de723a7850bc89908288990e6580 Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Wed, 30 Dec 2020 16:40:57 +0100 Subject: [PATCH] Day 17 (bug fix for higher dimensions) --- day17/part1.py | 4 ++-- day17/part2.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/day17/part1.py b/day17/part1.py index 631c9a2..f35dcc4 100644 --- a/day17/part1.py +++ b/day17/part1.py @@ -13,12 +13,12 @@ kernel[(1, )*DIMS] = 0 for _ in range(6): 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_active = np.logical_and(grid == 0, neighbors == 3) grid[set_inactive] = 0 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] print(np.sum(grid)) diff --git a/day17/part2.py b/day17/part2.py index 44fb3bd..b52a745 100644 --- a/day17/part2.py +++ b/day17/part2.py @@ -13,12 +13,12 @@ kernel[(1, )*DIMS] = 0 for _ in range(6): 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_active = np.logical_and(grid == 0, neighbors == 3) grid[set_inactive] = 0 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] print(np.sum(grid))