Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- operators = {'+': lambda a, b: a + b,
- '-': lambda a, b: a - b,
- '*': lambda a, b: a * b,
- '/': lambda a, b: a // b,
- }
- with open("Input_Day21.txt") as f:
- raw_data = [x.strip() for x in f]
- d = []
- for row in raw_data:
- id, op = row.split(": ")
- d.append((id, op))
- monkeys = {}
- while 'root' not in monkeys:
- for _m,_d in d:
- if _m in monkeys:
- continue
- if _d.isnumeric():
- monkeys[_m] = int(_d)
- else:
- m1, op, m2 = _d.split(' ')
- if (m1 in monkeys) and (m2 in monkeys):
- monkeys[_m] = operators[op](monkeys[m1], monkeys[m2])
- print(monkeys['root'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement