Send More Money (individual problem)

"Send more money" is a well-known puzzle. Each of the letters D,E,M,N,O,R,S and Y represents a different digit. Moreover, when each letter is mapped to its corresponding digit the equation SEND + MORE = MONEY holds. Since there are 8 letters to be solved, we can simply explore the 10*9*...*3 mappings of letters to digits. This could well be too slow. A little insight can simplify things. Clearly, SEND < 9999 and MORE < 9999. Thus MONEY < 19998 and hence M = 1. Now we have SEND + 1ORE = 1ONEY. Again SEND < 9999 and now 1ORE < 1999 so 1ONEY < 11998. Since M is already bound to 1, O must be bound to 0. A little more thought shows that S must be bound to 8 or 9, and that N = E + 1.

Write a Prolog predicate soln([D,E,M,N,O,R,S,Y]) that solves this puzzle by binding the correct digits to each of the variables in the list. You'll need to explain to Prolog that SEND is actually a number somehow calculated from the individual digits S, E, N, D, and so on. You should also use all of the insights described above to speed up your code (M must be 1, N = E + 1, etc.), but you should not add any further insights that you conceivably might discover on your own.

There is a unique solution to this puzzle.

Submit your code in a file called money.prolog.