diff options
author | dzwdz | 2022-12-21 09:24:20 +0100 |
---|---|---|
committer | dzwdz | 2022-12-21 09:24:20 +0100 |
commit | 7eb52708df38afad7fb6e6c62d6889655b2b6ecd (patch) | |
tree | 4d19dd635d1d67e6942defc4e59953d18723199c | |
parent | 529b8303374f68d88f993af55d53b8dd32d8ea13 (diff) |
day 21 part 1
-rw-r--r-- | 22.21/main.py | 24 |
1 files changed, 24 insertions, 0 deletions
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')) |