Help us understand the problem. What is going on with this article?

ASP 例題1 コイン問題(制約充足問題)

問題

1円硬貨,5円硬貨,10円硬貨を合計で15枚,それぞれを1枚以上持っている. 金額の合計は90円である. それぞれの硬貨を何枚持っているか?

回答

example1.lp
{coin_1yen(1..15)}=1.
{coin_5yen(1..15)}=1.
{coin_10yen(1..15)}=1.

:- not 15 = X + Y + Z, coin_1yen(X), coin_5yen(Y), coin_10yen(Z). 
:- not 90 = X + 5*Y + 10*Z, coin_1yen(X), coin_5yen(Y), coin_10yen(Z).

解説

{coin_1yen(1..15)}=1.は、「coin_1yenは1~15のいずれか一つが真」という意味

:-が先頭にくる場合は、制約であり、
:- not 15 = X + Y + Z, ...の場合、15 = X + Y + Zが必須条件になる。

参考

Coprisによる制約プログラミング入門
https://potassco.org/
https://qiita.com/yutaro-t/items/3a361aef5f9610ae4b8e

他の問題

ASP個人的ポータル

Ganesha
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした