mirror of
https://github.com/Crocmagnon/advent-of-code.git
synced 2024-12-24 23:01:55 +01:00
Solve day 8 part 1
This commit is contained in:
parent
8144ee812f
commit
2913ed34c5
2 changed files with 31 additions and 0 deletions
30
2019/day08-image.py
Normal file
30
2019/day08-image.py
Normal 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
1
2019/inputs/day08
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue