diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-21 13:03:08 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2022-12-21 13:03:08 +0000 |
commit | 7ab06039aba68d8b3e5445692acd4f82fff707a7 (patch) | |
tree | 763dc5db6b6ba80b4a1da0b3605ffe7014052727 | |
parent | 4e8eda742a6a34675232f8e8a3e54768d4efb95c (diff) | |
download | aoc2022-7ab06039aba68d8b3e5445692acd4f82fff707a7.tar.gz aoc2022-7ab06039aba68d8b3e5445692acd4f82fff707a7.tar.xz aoc2022-7ab06039aba68d8b3e5445692acd4f82fff707a7.zip |
21 all-in-one
-rw-r--r-- | 21.py | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -1,5 +1,6 @@ from functools import cache from utils import open_day +from subprocess import run, PIPE monkeys = {} with open_day(21) as f: @@ -26,7 +27,8 @@ def eval_monkey(m): print(eval_monkey('root')) -with open('21.z3', 'w') as f: +filename = '21.z3' +with open(filename, 'w') as f: f.write(''.join(f'(declare-const {monkey} Int)\n' for monkey in monkeys.keys())) for k, v in monkeys.items(): if k == 'humn': continue @@ -37,4 +39,6 @@ with open('21.z3', 'w') as f: print(f'(assert (= {k} {v}))', file=f) else: print(f'(assert (= {k} ({v[1]} {v[0]} {v[2]})))', file=f) - print('(check-sat)\n(get-model)', file=f) + print('(check-sat)\n(get-value (humn))', file=f) +r = run(['z3', filename], stdout=PIPE) +print(r.stdout.splitlines()[1].decode().strip('()').split()[1]) |