Solve 2016 day 10.
This commit is contained in:
parent
e528e84d36
commit
d2272e07f5
49
2016/d10.py
Normal file
49
2016/d10.py
Normal file
@ -0,0 +1,49 @@
|
||||
import sys
|
||||
from lib import *
|
||||
|
||||
data = open(0).read().strip()
|
||||
first = False
|
||||
|
||||
bots = {}
|
||||
outputs = {}
|
||||
while True:
|
||||
if not first and 0 in outputs and 1 in outputs and 2 in outputs:
|
||||
print(outputs[0] * outputs[1] * outputs[2])
|
||||
sys.exit(0)
|
||||
for line in data.splitlines():
|
||||
ints = str_to_ints(line)
|
||||
if len(ints) == 2:
|
||||
val, bot = ints
|
||||
if bot in bots:
|
||||
if val not in bots[bot]:
|
||||
bots[bot].append(val)
|
||||
else:
|
||||
bots[bot] = [val]
|
||||
elif len(ints) == 3:
|
||||
bot, lobot, hibot = ints
|
||||
if bot in bots and len(bots[bot]) == 2:
|
||||
loval = min(bots[bot])
|
||||
hival = max(bots[bot])
|
||||
bots[bot] = []
|
||||
if first and loval == 17 and hival == 61:
|
||||
print(bot)
|
||||
sys.exit(0)
|
||||
if "low to bot" in line:
|
||||
if lobot in bots:
|
||||
if loval not in bots[lobot]:
|
||||
bots[lobot].append(loval)
|
||||
else:
|
||||
bots[lobot] = [loval]
|
||||
if "high to bot" in line:
|
||||
if hibot in bots:
|
||||
if hival not in bots[hibot]:
|
||||
bots[hibot].append(hival)
|
||||
else:
|
||||
bots[hibot] = [hival]
|
||||
if "low to output" in line:
|
||||
outputs[lobot] = loval
|
||||
if "high to output" in line:
|
||||
outputs[hibot] = hival
|
||||
else:
|
||||
assert False
|
||||
|
Loading…
Reference in New Issue
Block a user