From 22776c0b9b4848153a41e7821abece708e01617e Mon Sep 17 00:00:00 2001 From: Dece Date: Sun, 8 Dec 2019 16:13:22 +0100 Subject: [PATCH] Day 8 --- 2019/day8.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2019/day8.py diff --git a/2019/day8.py b/2019/day8.py new file mode 100644 index 0000000..0b853e4 --- /dev/null +++ b/2019/day8.py @@ -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()