イフコンピュータ > IF/Prolog > 制約処理パッケージ > 例題プログラム > 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.

有限領域制約の例として、次の古典的な問題を考えてみましょう。 ``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

document: http://www.ifcomputer.co.jp/IFProlog/Constraints/ExamplePrograms/SendMoreMoney/print_jp.html
published 2008/8/19 update 1996/12/10 (c) 1996-2006 IF Computer Japan
IF Computer 〒113-0022 Tel 03-5814-3352 start (AT) ifcomputer.com
Customer Support 東京都文京区千駄木5-28-2   http://www.ifcomputer.co.jp
戻る> managed with ubiCMS