This commit is contained in:
Dece 2019-12-08 16:13:22 +01:00 committed by Adrien Abraham
parent b74ee2b52f
commit 22776c0b9b

21
2019/day8.py Normal file
View file

@ -0,0 +1,21 @@
WIDTH = 25
HEIGHT = 6
NUM_PIXELS = WIDTH * HEIGHT
def main():
with open("day8.txt", "rt") as input_file:
data = input_file.readlines()[0].rstrip()
num_layers = len(data) // NUM_PIXELS
layers = [data[i * NUM_PIXELS : (i+1) * NUM_PIXELS] for i in range(num_layers)]
# Part 1
least_zeros_layer = min(layers, key=lambda layer: sum(d == "0" for d in layer))
num_ones = sum(d == "1" for d in least_zeros_layer)
num_twos = sum(d == "2" for d in least_zeros_layer)
print("Result:", num_ones * num_twos)
if __name__ == "__main__":
main()