From 8844cd29f12a12e3891dbdc06b04e283b48040c7 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Wed, 21 Dec 2022 18:55:23 +0000 Subject: 21 sympy --- 21.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/21.py b/21.py index 03f94ee..40967a9 100644 --- a/21.py +++ b/21.py @@ -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])) -- cgit v1.2.3-54-g00ecf