You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
989 B
Python
33 lines
989 B
Python
#!/usr/bin/python
|
|
#
|
|
# Assign equal values to equal letters, and different values to
|
|
# different letters, in a way that satisfies the following sum:
|
|
#
|
|
# SEIS
|
|
# + SEIS
|
|
# ------
|
|
# DOZE
|
|
#
|
|
from constraint import *
|
|
|
|
def main():
|
|
problem = Problem()
|
|
problem.addVariables("seidoz", range(10))
|
|
problem.addConstraint(lambda s, e: (2*s)%10 == e, "se")
|
|
problem.addConstraint(lambda i, s, z, e: ((10*2*i)+(2*s))%100 == z*10+e,
|
|
"isze")
|
|
problem.addConstraint(lambda s, e, i, d, o, z:
|
|
2*(s*1000+e*100+i*10+s) == d*1000+o*100+z*10+e,
|
|
"seidoz")
|
|
problem.addConstraint(lambda s: s != 0, "s")
|
|
problem.addConstraint(lambda d: d != 0, "d")
|
|
problem.addConstraint(AllDifferentConstraint())
|
|
print "SEIS+SEIS=DOZE"
|
|
for s in problem.getSolutions():
|
|
print ("%(s)d%(e)d%(i)d%(s)s+%(s)d%(e)d%(i)d%(s)d="
|
|
"%(d)d%(o)d%(z)d%(e)d") % s
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|