diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-21 18:55:23 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-21 18:55:23 +0000 |
commit | 8844cd29f12a12e3891dbdc06b04e283b48040c7 (patch) | |
tree | f062b36ebf9f10a54dd3481897529eca6d7bca9c | |
parent | b30f6554b7e9ceba6ea3768e9aa6eb0fbd02411b (diff) | |
download | aoc2022-8844cd29f12a12e3891dbdc06b04e283b48040c7.tar.gz aoc2022-8844cd29f12a12e3891dbdc06b04e283b48040c7.tar.xz aoc2022-8844cd29f12a12e3891dbdc06b04e283b48040c7.zip |
-rw-r--r-- | 21.py | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -1,7 +1,7 @@ from operator import add, sub, mul, truediv, eq from subprocess import run, PIPE from utils import open_day -from z3 import Int, ArithRef, solve +from sympy import solve, Symbol monkeys = {} with open_day(21) as f: @@ -12,15 +12,15 @@ with open_day(21) as f: expr = int(expr[0]) monkeys[target] = expr -ops = { '+': add, '-': sub, '*': mul, '/': truediv, '==': eq } +ops = { '+': add, '-': sub, '*': mul, '/': truediv } def eval_monkey(m): expr = monkeys[m] - if isinstance(expr, int) or isinstance(expr, ArithRef): + if isinstance(expr, int) or isinstance(expr, Symbol): return expr return ops[expr[1]](eval_monkey(expr[0]), eval_monkey(expr[2])) print(int(eval_monkey('root'))) -monkeys['humn'] = Int('humn') -monkeys['root'][1] = '==' -solve(eval_monkey('root')) +monkeys['humn'] = Symbol('humn') +monkeys['root'][1] = '-' +print(int(solve(eval_monkey('root'), monkeys['humn'])[0])) |