aoc/2019/08/08.py

32 lines
704 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)