/* * CS 42, Fall 2012, Assignment 9 * * Logic Programming * * Note: This is a skeletal Prolog file, a09.pro, which you can complete * with your own solutions. * * Load this file from the command-line, using e.g. * * swipl -f a09.pro * * assuming you are using SWI-Prolog. * */ tbd :- nl, write('Answer to be Provided'), nl, fail. /* * Your m5 predicate */ m5(_X) :- tbd. m5test(0) :- m5([]). m5test(5) :- m5([1, 0, 1]). m5test(10) :- m5([1, 0, 1, 0]). m5test(15) :- m5([1, 1, 1, 1]). m5test(20) :- m5([1, 0, 1, 0, 0]). m5test(25) :- m5([1, 1, 0, 0, 1]). m5test(30) :- m5([1, 1, 1, 1, 0]). m5test(1) :- \+ m5([1]). m5test(2) :- \+ m5([1, 0]). m5test(3) :- \+ m5([1, 1]). m5test(4) :- \+ m5([1, 0, 0]). m5test(6) :- \+ m5([1, 1, 0]). m5test(7) :- \+ m5([1, 1, 1]). m5test(8) :- \+ m5([1, 0, 0, 0]). m5test(9) :- \+ m5([1, 0, 0, 1]). m5tests :- m5test(_), fail. m5tests. /***************************************************************************** * Movies Database predicates * * First download the file movies.pro from the course website and put it * in your working directory. */ /* * The following will load movies.pro into Prolog from your working directory. */ :- ensure_loaded('movies.pro'). % ans0 is solved for you % ans0 is true for the director of ['American Beauty', 1999]? ans0(Director) :- movie(['American Beauty', 1999], Director, _). % ans1 is true for any movie [Title, Year] in which Harrison Ford played a role. ans1(_Movie) :- tbd. % ans2 is true for any movie [Title, Year] having comedy as a descriptor. ans2(_Movie) :- tbd. % ans3 is true for the title of two movies with the same title but produced in different years. ans3(_Title) :- tbd. % ans4 is true for an actress or actor born in New Jersey ans4(_Person) :- tbd. % ans5 is true for an actress or actor born before 1950. ans5(_Person) :- tbd. % ans6 is true for an actress or actor born in New Jersey before 1950. ans6(_Person) :- tbd. % ans7 is true for a pair of an actor and actress who played together in the same movie. ans7(_Actor, _Actress) :- tbd. % ans8 is true for a pair of an actor and actress who played together in more than one movie. ans8(_Actor, _Actress) :- tbd. % ans9 is true for an actor or actress who both directed and played in the same movie. ans9(_Person) :- tbd. % ans10 lists actors and actresses together in order of increasing birth year, giving the year first. ans10(_List) :- tbd. % ans11 is true for the youngest actress or actor (give multiple results if there is a tie). ans11(_Person) :- tbd. % ans12(Degree, Person1, Person2) is true if Person1 is within Degree degrees of Person2. % within degree 1 means that Person1 and Person2 acted in the same movie. % within degree N > 1 means either Person1 is within degree N-1 of Person2, or % Person1 acted in a movie with some Person3, and Person2 is within degree N-1 of Person3. % % Degree is assumed to be instantiated. It is preferable that each instance of Person2 be % given only once for an instance of Person1, and vice-versa. ans12(_N, _Person1, _Person2) :- tbd. % ans13(N) means that N is the number of actors and actresses not within 6 degress of Kevin Bacon. ans13(_N) :- tbd. tests1 :- nl, write('ans1: '), ans1(Movie), nl, write(Movie), nl. tests1 :- nl, write('ans2: '), ans2(Movie), nl, write(Movie), nl. tests1 :- nl, write('ans3: '), ans3(Title), nl, write(Title), nl. tests1 :- nl, write('ans4: '), ans4(Person), nl, write(Person), nl. tests1 :- nl, write('ans5: '), ans5(Person), nl, write(Person), nl. tests1 :- nl, write('ans6: '), ans6(Person), nl, write(Person), nl. tests1 :- nl, write('ans7: '), ans7(Actor, Actress), nl, write(Actor), nl, write(' '), nl, write(Actress), nl. tests1 :- nl, write('ans8: '), ans8(Actor, Actress), nl, write(Actor), nl, write(' '), nl, write(Actress), nl. tests1 :- nl, write('ans9: '), ans9(Person), nl, write(Person), nl. tests1 :- nl, write('ans10: '), ans10(List), nl, write(List), nl. tests1 :- nl, write('ans11: '), ans11(Person), nl, write(Person), nl. tests1 :- nl, write('ans12: '), ans12(1, 'Liv Tyler', Person), nl, write(1), write(': '), nl, write(Person), nl. tests1 :- nl, write('ans12: '), ans12(2, 'Liv Tyler', Person), nl, write(2), write(': '), nl, write(Person), nl. tests1 :- nl, write('ans12: '), ans12(3, 'Liv Tyler', Person), nl, write(3), write(': '), nl, write(Person), nl. tests1 :- nl, write('ans13: '), ans13(N), nl, write(N), nl. test :- tests1, fail. test :- true.