Mercurial > repos > other > SevenLanguagesInSevenWeeks
annotate 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 |
rev | line source |
---|---|
55
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 % Make a KB of books and authors and query it. |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 book(the_long_earth). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 book(night_watch). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 book(lord_of_the_rings). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 book(route_666). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 book(krokodil_tears). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 author(terry_pratchett). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 author(stephen_baxter). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 author(jrr_tolkein). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 author(jack_yeovil). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 wrote(terry_pratchett, the_long_earth). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 wrote(stephen_baxter, the_long_earth). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 wrote(terry_pratchett, night_watch). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 wrote(jrr_tolkein, lord_of_the_rings). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 wrote(jack_yeovil, route_666). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 wrote(jack_yeovil, krokodil_tears). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 collaborated(Author1, Author2) :- \+(Author1 = Author2), author(Author1), author(Author2), |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 wrote(Author1, Book), wrote(Author2, Book), book(Book). |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 % collaborated(terry_pratchett, stephen_baxter). returns true, but collaborated(Author1, Author2). just says "no", as does |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 % collaborated(terry_pratchett, OtherAuthor). - for some reason it isn't filling in answers. |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 % |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 % If I remove "\+(Author1 = Author2)" then it successfully returns stephen_baxter for terry_pratchett but also returns |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 % Pratchett himself as a valid answer as well. |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 % |
3a20e8b49bc4
Write some self-study code with an additional stretch rule to find collaborations
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 % wrote(terry_pratchett, Book). works to return all books by an author, though. |