sitelogo
Send More Money
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.

有限領域制約の例として、次の古典的な問題を考えてみましょう。 ``SEND MORE MONEY'' 問題では、SEND + MORE = MONEYの式の中で、 個々のアルファベットは0から9までの整数のいずれかを取る変数です。

従来、この問題を解決するのには長い探索時間がかかりました。とい うのは、それぞれの変数に対して、可能な整数を順にすべて考慮して 解答を出したからです。制約を使用すれば、値が伝達され、解答が 直接計算されます。

:- 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


戻る 続く..
冒頭へ managed with ubiCMS