The Constraint Programming Solver

Send More Money

The Send More Money problem consists of finding unique digits for the letters D, E, M, N, O, R, S, and Y such that S and M are different from zero (no leading zeros) and the following equation is satisfied:

S E N D
+ M O R E
M O N E Y

You can use the CLP solver to formulate this problem as a CSP by using an integer variable to represent each letter in the expression. The comments before each statement in the following code introduce variables, domains, and constraints:


/*  Send More Money  */
proc optmodel;
   /* Declare all variables as integer. */
   var S integer, E integer, N integer, D integer, M integer, O integer,
       R integer, Y integer;
   /* Set all domains to between 0 and 9. Domains are unbounded by default.
      Always declare domains to be as tight as possible. */
   for {j in 1.._NVAR_} do;
      _VAR_[j].lb = 0;
      _VAR_[j].ub = 9;
   end;
   /* Describe the arithmetic constraint.*/
   con Arithmetic:           1000*S + 100*E + 10*N + D
                 +           1000*M + 100*O + 10*R + E
                 = 10000*M + 1000*O + 100*N + 10*E + Y;
   /* Forbid leading letters from taking the value zero.
      Constraint names are optional. */
   con S ne 0;
   con M ne 0;
   /* Require all variables to take distinct values. */
   con alldiff(S E N D M O R Y);

   solve;
   print S E N D M O R Y;
quit;

The domain of each variable is the set of digits 0 through 9. The VAR statement identifies the variables in the problem. The Arithmetic constraint defines the linear constraint SEND + MORE = MONEY and the restrictions that S and M cannot take the value 0. (Alternatively, you can simply specify the domain for S and M as greater-than-or-equal-to 1 less-than-or-equal-to 9 in the VAR statement.) Finally, the ALLDIFF predicate enforces the condition that the assignment of digits should be unique.

The PRINT statement produces the solution output as shown in Figure 1.

Figure 1: Solution to SEND + MORE = MONEY

The OPTMODEL Procedure

Problem Summary
Objective SenseMinimization
Objective Function(0)
Objective TypeConstant
  
Number of Variables8
Bounded Above0
Bounded Below0
Bounded Below and Above8
Free0
Fixed0
Binary0
Integer8
  
Number of Constraints4
Linear LE (<=)0
Linear EQ (=)1
Linear GE (>=)0
Linear LT (<)0
Linear NE (~=)2
Linear GT (>)0
Linear Range0
Alldiff1
Cumulative0
Element0
GCC0
Lexico (<=)0
Lexico (<)0
Pack0
Reify0
  
Constraint Coefficients10

Solution Summary
SolverCLP
Variable SelectionMINR
Objective Function(0)
Solution StatusSolution Limit Reached
Objective Value0
  
Solutions Found1
Presolve Time0.00
Solution Time0.01

SENDMORY
95671082


The CLP solver determines the following unique solution to this problem:

9 5 6 7
+ 1 0 8 5
1 0 6 5 2

Last updated: September 09, 2026