/** : "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. A very naive solve is to instantiate each letter with an unique digit and test the equation. Since there are 8 letters to be solved, it simply explore the 10*9*...*3 mappings of letters to digits. */ assign_digits([], _List). assign_digits([D|Ds], List):- select(D, List, NewList), assign_digits(Ds, NewList). solvSlow( [D,E,M,N,O,R,S,Y]) :- Lst = [S,E,N,D,M,O,R,Y], Digits = [0,1,2,3,4,5,6,7,8,9], assign_digits(Lst, Digits), M > 0, S > 0, 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E =:= 10000*M + 1000*O + 100*N + 10*E + Y, write(Lst). % -------------------------- /* ?- solv([D,E,M,N,O,R,S,Y]). [9, 5, 6, 7, 1, 0, 8, 2] D = 7, E = 5, M = 1, N = 6, O = 0, R = 8, S = 9, Y = 2 */