example/send more money: rework a bit
@@ -12,16 +12,17 @@ from cpmpy import *
import numpy as np
# Construct the model.
-s,e,n,d,m,o,r,y = IntVar(0,9, 8)
+s,e,n,d,m,o,r,y = intvar(0,9, 8)
-constraints = []
-constraints += [ alldifferent([s,e,n,d,m,o,r,y]) ]
-constraints += [ sum( [s,e,n,d] * np.flip(10**np.arange(4)) )
- + sum( [m,o,r,e] * np.flip(10**np.arange(4)) )
- == sum( [m,o,n,e,y] * np.flip(10**np.arange(5)) ) ]
-constraints += [ s > 0, m > 0 ]
+model = Model(
+ AllDifferent([s,e,n,d,m,o,r,y]),
+ ( sum( [s,e,n,d] * np.array([ 1000, 100, 10, 1]) ) \
+ + sum( [m,o,r,e] * np.array([ 1000, 100, 10, 1]) ) \
+ == sum( [m,o,n,e,y] * np.array([10000, 1000, 100, 10, 1]) ) ),
+ s > 0,
+ m > 0,
+)
-model = Model(constraints)
print(model)
print("") # blank line
