-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday08.py
37 lines (22 loc) · 821 Bytes
/
day08.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from util import Day
import numpy as np
import matplotlib.pyplot as plt
def shaper(data, wide, tall):
return np.array([int(x) for x in data[0]]).reshape(-1, tall, wide)
def min_layer(data, axis=0):
return np.argmax([np.count_nonzero(data[i, :, :]) for i in range(data.shape[0])])
def hash(data, layer):
return np.sum(data[layer, :, :] == 1) * np.sum(data[layer, :, :] == 2)
def sif_decode(data):
return np.take_along_axis(data, np.expand_dims(np.argmax(data < 2, axis=0), 0), 0).squeeze()
if __name__ == "__main__":
# Part 1
part1 = Day(8, 1)
part1.load(typing=str)
part1.data = shaper(part1.data, 25, 6)
part1.bake()
layer_i = min_layer(part1.data)
part1.answer(hash(part1.data, layer_i), v=1)
# Part 2
plt.imshow(sif_decode(part1.data))
plt.show()