You need to write a program that solves this simple puzzle:

where different letters represent different digits.

The class SendMoreMoney extends JavaSolver and defines this problem in the following method:

First it creates 8 different constrained integer variables with possible values from 0 to 9. Then it puts these 8 variables into the array “vars” and posts a predefined constraint csp.postAllDiff(vars) forcing all these variables to take different values. And finally it expresses the main equation as

1000S+100E+10N+D + 1000M+100M+10R+E – 10000M-1000O-100N-10E-Y = 0

The next SendMoreMoney’s method is responsible for a nice print of the solution:

This method will be automatically called when a solution is found.

And finally, here is the main method that creates an instance of the class SendMoreMoney and calls its methods define() and solve(). The method solve() is used when a problem does not have an optimization objective and you want to find a feasible solution.

Here are the execution results: