1 Star 0 Fork 0

awumiao/learn-z3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
2-logical-reasoning.py 726 Bytes
一键复制 编辑 原始数据 按行查看 历史
Igorxp5 提交于 2022-07-16 21:11 +08:00 . fixed 2-logical-reasoning.py not youngest brother
#!/usr/bin/env python3
import z3
"""
John, Aries, and Joseph are brothers with different ages. Who is the youngest if the following statements are true?
I. Aries is the oldest.
II. John is not the youngest.
"""
"""
Ages: 0 1 2
"""
def min(li):
m = li[0]
for i in li[1:]:
m = z3.If(i < m, i, m)
return m
def max(li):
m = li[0]
for i in li[1:]:
m = z3.If(i > m, i, m)
return m
john, aries, joseph = z3.Ints('john aries joseph')
bros = [john, aries, joseph]
solver = z3.Solver()
solver.add(z3.Distinct(bros))
solver.add([z3.And(i >= 0, i <= 2) for i in bros])
solver.add(aries == max(bros))
solver.add(john != min(bros))
if solver.check() == z3.sat:
print(solver.model())
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Awu-Miao/learn-z3.git
[email protected]:Awu-Miao/learn-z3.git
Awu-Miao
learn-z3
learn-z3
main

搜索帮助