LoginSignup
0
0

More than 3 years have passed since last update.

ASP 例題2 コイン問題2

Last updated at Posted at 2020-04-05

問題

以下のユーロ硬貨を持っているとする(総和は148セントになる)。
20セント硬貨 4枚
10セント硬貨 4枚
5セント硬貨 4枚
2セント硬貨 4枚
合計がちょうど93セントになる組合せはあるだろうか?
各3枚の場合はどうか?

回答

example2.lp
num(4).
{coin_2cent(1..X)}=1:- num(X).
{coin_5cent(1..X)}=1:- num(X).
{coin_10yen(1..X)}=1:- num(X).
{coin_20yen(1..X)}=1:- num(X).

:- not 93 = 2*A + 5*B + 10*C + 20*D, coin_2cent(A), coin_5cent(B), coin_10yen(C), coin_20yen(D).

解説

num(4)で各コインの枚数を指定する。
{coin_2cent(1..X)}=1:- num(X).
{coin_2cent(1..4)}=1:- num(4).となり、2セント硬貨は1~4枚のいずれか使用する、という解釈になる。

参考

Coprisによる制約プログラミング入門
https://potassco.org/

他の問題

ASP個人的ポータル

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0