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)