Open
Description
The code in examples/abc.py has a bug. The minvalue
variable is actually never updated in the loop so it returns the wrong solution. The optimal solution to the problem is actually a=1, b=9, c=9
which achieves a value of 199/19=10.47
(better than 999/27=37
) .
def solve():
problem = Problem()
problem.addVariables("abc", range(1, 10))
problem.getSolutions()
minvalue = 999 / (9 * 3)
minsolution = {}
for solution in problem.getSolutions():
a = solution["a"]
b = solution["b"]
c = solution["c"]
value = (a * 100 + b * 10 + c) / (a + b + c)
if value < minvalue:
minsolution = solution
return minvalue, minsolution
Easy fix. Just need to remember to update minvalue
.
if value < minvalue:
minvalue = value
minsolution = solution
The test case has the wrong solution too so will need to update that as well.
Metadata
Metadata
Assignees
Labels
No labels