Many to Many - Prolog

13 views
Skip to first unread message

Diogo Oliv

unread,
Sep 23, 2015, 12:59:37 PM9/23/15
to SWI-Prolog
In Prolog I have a db like this:

invoice(number,item,product,value).

invoice('2015/01',1,coffee,100).
invoice('2015/02',1,water,50).
invoice('2015/02',2,coffee,100).
invoice('2015/03',1,milk,80).
invoice('2015/03',2,cake,150).


I need to ask Prolog this question: How many invoices have NO coffee or water ? In this case the answer would be 1 (the invoice number 2015/03)

Other Question I would like to do is: What are the invoices that have NO coffee or water ?

Can anyone help me getting there?

Jacco van Ossenbruggen

unread,
Sep 23, 2015, 1:16:11 PM9/23/15
to Diogo Oliv, SWI-Prolog
On 23 Sep 2015, at 18:59, Diogo Oliv <cdio...@gmail.com> wrote:


Other Question I would like to do is: What are the invoices that have NO coffee or water ?




With the risk of this being a homework spoiler: Is this what you mean with the second question?  

Jacco (playing with swish notebooks)

PS: Homework still to do: 
- I left the first question open …
- find a solution without using the may-be-not-so-portable distinct/2 predicate :-)


Reply all
Reply to author
Forward
0 new messages