<filename>2019/p8/main2.py
#from aocd.models import Puzzle
import numpy as np
from matplotlib import pyplot as plt

#puzzle = Puzzle(year=2019, day=8)
f = open('input')
line = f.readline().strip()
data = [int(i) for i in line]
shape = (int(len(data) / 6 / 25), 6, 25)

# build 3d array
arr = np.array(data).reshape(shape)

# part 1
min_zero = min(arr, key=lambda x: len(x[x == 0]))
ones = len(min_zero[min_zero == 1])
twos = len(min_zero[min_zero == 2])
print("the result of part one: {} * {} = {}".format(ones, twos, ones * twos))

# part 2
def find_value(n):
    index = 0
    while n[index] == 2: index += 1
    return n[index]

message = np.apply_along_axis(find_value, 0, arr)
print(message)
plt.imshow(message)
plt.show()
<filename>2019/p8/main2.py
#from aocd.models import Puzzle
import numpy as np
from matplotlib import pyplot as plt

#puzzle = Puzzle(year=2019, day=8)
f = open('input')
line = f.readline().strip()
data = [int(i) for i in line]
shape = (int(len(data) / 6 / 25), 6, 25)

# build 3d array
arr = np.array(data).reshape(shape)

# part 1
min_zero = min(arr, key=lambda x: len(x[x == 0]))
ones = len(min_zero[min_zero == 1])
twos = len(min_zero[min_zero == 2])
print("the result of part one: {} * {} = {}".format(ones, twos, ones * twos))

# part 2
def find_value(n):
    index = 0
    while n[index] == 2: index += 1
    return n[index]

message = np.apply_along_axis(find_value, 0, arr)
print(message)
plt.imshow(message)
plt.show()
#from aocd.models import Puzzle #puzzle = Puzzle(year=2019, day=8) # build 3d array # part 1 # part 2