this is really hard question. I have an exam. And questions will be like that. They are really hard. These are my database:
director (martinscorsese, american, 1, 51).
director (hayaomiyazaki, japanese, 1, 23).
director (stevenspielberg, american, 3, 49).
director (georgelucas, american, 0, 19).
director (christophernolan, american, 0, 10).
watched(departed, [george, jane, eric]).
watched(theaviator, [jane,eric]).
watched(swrevengeofthesith, [paul,eric]).
watched(transformers, [paul, george, jane]).
I want to implement the predicate audiance(A,N,O,L1) that returns the list of all movies (L1) not yet seen by anyone in A, which has been directed by a director of Nationality N who won at least O oscars. The list L must not contain any duplicates.
audiance([paul],american,1,X). returns X=[ departed, theaviator ]
audiance([paul,george],N,0,X). returns N=american X= [theaviator]
audiance(X,american,0,[swrevengeofthesith]). returns X=[jane,george]
audiance([paul,george,jane],N,0,X). returns false
plz help me :))
i could just post code but i dont think it would help to pass the exam
you should divide the problem into smaller and easier sub-problems.
1) a predicate not_seen(Movie,People) that returns true only if nobody in the list People have seen the Movie
2) a predicate director_nationality(Movie, Nationality) that returns true if the director of the Movie has the given nationality
3) a predicate director_oscars(Director, Num_Oscars) that returns true if the director has won at least Num_Oscars oscars
then you have to combine all these in one predicate which you can call movie_requirements(Movie).
finally, to find all the movies you can use findall/3
to ensure that there wont be any doublicates you could use sort/2 that will remove any duplicates or use bagof/3 instead of findall/3
check member/2 and the other built-in predicates for lists