comparison 3-Prolog/day1-self-study.pl @ 55:3a20e8b49bc4

Write some self-study code with an additional stretch rule to find collaborations
author IBBoard <dev@ibboard.co.uk>
date Tue, 26 Sep 2017 20:26:45 +0100
parents
children 2bbb377ddeb0
comparison
equal deleted inserted replaced
54:91d02b3d74f8 55:3a20e8b49bc4
1 % Make a KB of books and authors and query it.
2 book(the_long_earth).
3 book(night_watch).
4 book(lord_of_the_rings).
5 book(route_666).
6 book(krokodil_tears).
7 author(terry_pratchett).
8 author(stephen_baxter).
9 author(jrr_tolkein).
10 author(jack_yeovil).
11 wrote(terry_pratchett, the_long_earth).
12 wrote(stephen_baxter, the_long_earth).
13 wrote(terry_pratchett, night_watch).
14 wrote(jrr_tolkein, lord_of_the_rings).
15 wrote(jack_yeovil, route_666).
16 wrote(jack_yeovil, krokodil_tears).
17
18 collaborated(Author1, Author2) :- \+(Author1 = Author2), author(Author1), author(Author2),
19 wrote(Author1, Book), wrote(Author2, Book), book(Book).
20 % collaborated(terry_pratchett, stephen_baxter). returns true, but collaborated(Author1, Author2). just says "no", as does
21 % collaborated(terry_pratchett, OtherAuthor). - for some reason it isn't filling in answers.
22 %
23 % If I remove "\+(Author1 = Author2)" then it successfully returns stephen_baxter for terry_pratchett but also returns
24 % Pratchett himself as a valid answer as well.
25 %
26 % wrote(terry_pratchett, Book). works to return all books by an author, though.