aoc/2019/08/08.py

32 lines
704 B
Python
Raw Normal View History

2020-12-11 21:16:01 +00:00
from textwrap import wrap
with open("input.txt","r") as f:
width = 25
height = 6
layersize = width * height
data = f.read()
layers = wrap(data, layersize)
zeros = [layer.count("0") for layer in layers]
i = zeros.index(min(zeros))
part1 = layers[i].count("1") * layers[i].count("2")
print(part1)
top = []
for i, pixel in enumerate(layers[0]):
n = 0
while pixel == "2":
pixel = layers[n][i]
n += 1
top.append(pixel)
def print_image(layer, width, height):
output = ''
for x in layer:
output += x
output = output.replace("0","")
output = output.replace("1","")
output = wrap(output, width)
for line in output:
print(line)
print_image(top, width, height)