代码拉取完成,页面将自动刷新
#!/usr/bin/env python3
import z3
"""
There is an assignment of unique digits to letters such that the equation `send + more = money` holds.
Find an assignment of the digits to make this true.
"""
digits = z3.Ints('o d n m e y s r')
o, d, n, m, e, y, s, r = digits
def join_numbers(l):
return z3.Sum([10**i * v for i, v in enumerate(l[::-1])])
send = join_numbers([s, e, n, d])
more = join_numbers([m, o, r, e])
money = join_numbers([m, o, n, e, y])
solver = z3.Solver()
solver.add(z3.Distinct(digits))
solver.add(send + more == money)
solver.add([z3.And(i >= 0, i <= 9) for i in digits])
solver.add([s > 0, m > 0])
if solver.check() == z3.sat:
m = solver.model()
print(f'{m}\n{m.eval(send)} + {m.eval(more)} = {m.eval(money)}')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。