代码拉取完成,页面将自动刷新
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())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。