Solve day 8 part 1

This commit is contained in:
Gabriel Augendre 2020-03-06 17:19:52 +01:00
parent 8144ee812f
commit 2913ed34c5
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 31 additions and 0 deletions

30
2019/day08-image.py Normal file
View file

@ -0,0 +1,30 @@
import math
def main():
width = 25
height = 6
with open("inputs/day08") as f:
data = f.readline().strip()
layers = []
layer_size = width * height
position = 0
layer = data[position : position + layer_size]
number_of_zero_digits = math.inf
layer_index = -1
while layer:
count = layer.count("0")
if count < number_of_zero_digits:
layer_index = int(position / layer_size)
number_of_zero_digits = count
layers.append(layer)
position += layer_size
layer = data[position : position + layer_size]
print(layer_index)
layer = layers[layer_index]
print(layer.count("1") * layer.count("2"))
if __name__ == "__main__":
main()

1
2019/inputs/day08 Normal file

File diff suppressed because one or more lines are too long