Solution to problem 10 part 1 in Python

This commit is contained in:
David Doblas Jiménez 2022-05-09 20:20:49 +02:00
parent 711995922e
commit 1ae2df34d4

View File

@ -45,6 +45,7 @@
import collections
import re
from copy import copy
with open("files/P10.txt") as f:
instructions = [line for line in f.read().strip().split("\n")]
@ -63,12 +64,18 @@ for line in instructions:
def part_1():
while bots_dic:
for k, v in bots_dic.items():
if len(v) == 2:
v1, v2 = sorted(bots_dic.pop(k))
if v1 == 17 and v2 == 61:
print(k)
found = False
while not found:
for bot, value in dict(bots_dic).items():
if len(value) == 2:
low_val, high_val = sorted(bots_dic.pop(bot))
if low_val == 17 and high_val == 61:
print(f"The bot responsible has number {bot}")
found = True
break
(_, low), (_, high) = pipeline[bot]
bots_dic[low].append(low_val)
bots_dic[high].append(high_val)
if __name__ == "__main__":