THIS IS A PROLOG QUESTION ! PLEASE ANSWER IT WITH PROLOG . For the purposes of t
ID: 3700279 • Letter: T
Question
THIS IS A PROLOG QUESTION ! PLEASE ANSWER IT WITH PROLOG .
For the purposes of the examples in this question, assume that the following facts have been loaded into Prolog:
Write a predicate all_like_all(Who_List, What_List) that takes a list of people Who_List and a list of items What_List and succeeds if every person in Who_List likes every item in What_List, according to the predicate likes(Who, What). Your predicate should also succeed if eitherWho_List or What_List is empty. Examples:
Note that your all_like_all predicate will be tested with different likes(Who, What) facts to those in the examples.
Explanation / Answer
%base condition: all_like_all([] , [_|_]). all_like_all([_|_], []). %recursive condition: all_like_all([First_people|Rest_people], [First_fruit|Rest_fruit]):- likes(First_people, First_fruit), all_like_all([First_people|Rest_people], Rest_fruit), all_like_all(Rest_people, [First_fruit| Rest_fruit]).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.