File tree 2 files changed +25
-1
lines changed
Filter options
2 files changed +25
-1
lines changed
Original file line number Diff line number Diff line change 18
18
| [ 14] ( https://adventofcode.com/2020/day/14 ) | Docking Data| [ py] ( /day14/main.py ) |
19
19
| [ 15] ( https://adventofcode.com/2020/day/15 ) | Rambunctious Recitation| [ py] ( /day15/main.py ) , [ alt] ( /day15/alt.py ) |
20
20
| [ 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 ) |
22
22
| [ 18] ( https://adventofcode.com/2020/day/18 ) | -| -|
23
23
| [ 19] ( https://adventofcode.com/2020/day/19 ) | -| -|
24
24
| [ 20] ( https://adventofcode.com/2020/day/20 ) | -| -|
Original file line number Diff line number Diff line change
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 ))
You can’t perform that action at this time.
0 commit comments