IF Computer > IF/Prolog > Constraint Technology Package > Example Programs > Send More Money

Send More Money

IF/Prolog by Siemens
MINERVA superseeded IF/Prolog. Please see http://www.ifcomputer.co.jp/MINERVA for details.

We discontinued to sell IF/Prolog Dec 31. 2003. For current customers, we continue to provide professional support for IF/Prolog until Dec 31, 2008.

To illustrate finite domain constraints we consider the classic "SEND MORE MONEY" prob- lem where the three words represent a sum (SEND + MORE = MONEY) and each letter a variable which takes one of the integers 0 to 9.

Traditionally this problem takes a considerable amount of search time to find the solution by considering all possible integer values for each variable in turn. Using constraints, the values are propagated and the solution is calculated directly.

:-  import(const_domain).

send([[S,E,N,D], [M,O,R,E], [M,O,N,E,Y]]) :- Digits = [S,E,N,D,M,O,R,Y], Carries = [C1,C2,C3,C4], Digits in 0..9, Carries in 0..1,

M ?= C4, O + 10 * C4 ?= M + S + C3, N + 10 * C3 ?= O + E + C2, E + 10 * C2 ?= R + N + C1, Y + 10 * C1 ?= E + D,

M ?>= 1, S ?>= 1, all_distinct(Digits), label(Digits).

[user] ?- send(X). X = [[9,5,6,7],[1,0,8,5],[1,0,6,5,2]] yes

document: http://www.ifcomputer.co.jp/IFProlog/Constraints/ExamplePrograms/SendMoreMoney/print_de.html
published 2008/10/6 update 1996/12/10 (c) 1996-2006 IF Computer Japan
IF Computer 5-28-2 Sendagi, Bunkyo-ku Tel +81-3-5814-3352 start (AT) ifcomputer.com
Customer Support Tokyo 113-0022 Japan   http://www.ifcomputer.com
Back> managed with ubiCMS