From 7eb52708df38afad7fb6e6c62d6889655b2b6ecd Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 21 Dec 2022 09:24:20 +0100 Subject: day 21 part 1 --- 22.21/main.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 22.21/main.py diff --git a/22.21/main.py b/22.21/main.py new file mode 100644 index 0000000..2ac7c15 --- /dev/null +++ b/22.21/main.py @@ -0,0 +1,24 @@ +from sys import stdin + +monkeys = {} + +for line in stdin: + out = line[:4] + parts = line[6:].split() + if len(parts) == 1: parts = int(parts[0]) + monkeys[out] = parts + +def get(k): + m = monkeys[k] + if type(m) != int: + a = get(m[0]) + b = get(m[2]) + op = m[1] + if op == '+': m = a + b + if op == '-': m = a - b + if op == '*': m = a * b + if op == '/': m = a // b + monkeys[k] = m + return m + +print(get('root')) -- cgit 1.4.1-2-gfad0