Skip to content

Commit 5982148

Browse files
committed
day 17
1 parent f04f74f commit 5982148

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
|[14](https://adventofcode.com/2020/day/14)|Docking Data|[py](/day14/main.py)|
1919
|[15](https://adventofcode.com/2020/day/15)|Rambunctious Recitation|[py](/day15/main.py), [alt](/day15/alt.py)|
2020
|[16](https://adventofcode.com/2020/day/16)|Ticket Translation|[py](/day16/main.py), [alt](/day16/alt.py)|
21-
|[17](https://adventofcode.com/2020/day/17)|-|-|
21+
|[17](https://adventofcode.com/2020/day/17)|Conway Cubes|[py](/day17/main.py)|
2222
|[18](https://adventofcode.com/2020/day/18)|-|-|
2323
|[19](https://adventofcode.com/2020/day/19)|-|-|
2424
|[20](https://adventofcode.com/2020/day/20)|-|-|

day17/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
from scipy.ndimage import generic_filter
3+
4+
with open("input.txt") as f:
5+
lines = [list(x.strip()) for x in f]
6+
7+
def f(x):
8+
if x[len(x) // 2] == 0:
9+
if np.sum(x) == 3: return 1
10+
else: return 0
11+
else:
12+
if np.sum(x) in (3,4): return 1
13+
else: return 0
14+
15+
d = 20
16+
for dims in [3,4]:
17+
a = (np.array(lines) == "#").astype(np.uint8)
18+
for _ in range(dims-2):
19+
a = np.reshape(a, (1,)+a.shape)
20+
arr = np.pad(a, (d-a.shape[0]) // 2)
21+
kernel = np.ones([3]*dims, dtype=np.uint8)
22+
for i in range(6):
23+
arr = generic_filter(arr, f, footprint=kernel, mode="constant", cval=0)
24+
print(np.sum(arr))

0 commit comments

Comments
 (0)