# HG changeset patch # User IBBoard # Date 1506454005 -3600 # Node ID 3a20e8b49bc4facab2da21a03ac6d5b2306d98ba # Parent 91d02b3d74f815970fd8291596e9da350685f651 Write some self-study code with an additional stretch rule to find collaborations diff -r 91d02b3d74f8 -r 3a20e8b49bc4 3-Prolog/day1-self-study.pl --- /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