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.
typesetting/csp/csp/python-constraint/trials/abcd.py

30 lines
572 B
Python

#!/usr/bin/python
#
# What's the minimum value for:
#
# ABC
# -------
# A+B+C
#
# From http://www.umassd.edu/mathcontest/abc.cfm
#
from constraint import *
def main():
problem = Problem()
problem.addVariables("abc", range(1,10))
results = []
for solution in problem.getSolutions():
a = solution["a"]
b = solution["b"]
c = solution["c"]
results.append((((a*100) + (b*10) + c) / (a + b + c + 0.0), (a*100) + (b*10) + c))
results.sort()
print results[0]
if __name__ == "__main__":
main()