Solution to problem 10 part 1 in Python
This commit is contained in:
@@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
import re
|
import re
|
||||||
|
from copy import copy
|
||||||
|
|
||||||
with open("files/P10.txt") as f:
|
with open("files/P10.txt") as f:
|
||||||
instructions = [line for line in f.read().strip().split("\n")]
|
instructions = [line for line in f.read().strip().split("\n")]
|
||||||
@@ -63,12 +64,18 @@ for line in instructions:
|
|||||||
|
|
||||||
|
|
||||||
def part_1():
|
def part_1():
|
||||||
while bots_dic:
|
found = False
|
||||||
for k, v in bots_dic.items():
|
while not found:
|
||||||
if len(v) == 2:
|
for bot, value in dict(bots_dic).items():
|
||||||
v1, v2 = sorted(bots_dic.pop(k))
|
if len(value) == 2:
|
||||||
if v1 == 17 and v2 == 61:
|
low_val, high_val = sorted(bots_dic.pop(bot))
|
||||||
print(k)
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user