changeset 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 91d02b3d74f8
children 2bbb377ddeb0
files 3-Prolog/day1-self-study.pl
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/3-Prolog/day1-self-study.pl	Tue Sep 26 20:26:45 2017 +0100
@@ -0,0 +1,26 @@
+% Make a KB of books and authors and query it.
+book(the_long_earth).
+book(night_watch).
+book(lord_of_the_rings).
+book(route_666).
+book(krokodil_tears).
+author(terry_pratchett).
+author(stephen_baxter).
+author(jrr_tolkein).
+author(jack_yeovil).
+wrote(terry_pratchett, the_long_earth).
+wrote(stephen_baxter, the_long_earth).
+wrote(terry_pratchett, night_watch).
+wrote(jrr_tolkein, lord_of_the_rings).
+wrote(jack_yeovil, route_666).
+wrote(jack_yeovil, krokodil_tears).
+
+collaborated(Author1, Author2) :- \+(Author1 = Author2), author(Author1), author(Author2),
+    wrote(Author1, Book), wrote(Author2, Book), book(Book).
+% collaborated(terry_pratchett, stephen_baxter). returns true, but collaborated(Author1, Author2).  just says "no", as does
+% collaborated(terry_pratchett, OtherAuthor). - for some reason it isn't filling in answers.
+%
+% If I remove "\+(Author1 = Author2)" then it successfully returns stephen_baxter for terry_pratchett but also returns
+% Pratchett himself as a valid answer as well.
+%
+% wrote(terry_pratchett, Book). works to return all books by an author, though.
\ No newline at end of file