I’m having a bit of a problem with a Prolog exercise.
Assume i have a list of actors that have won oscars. Like this:
(steven spielberg, steven spielberg, francis ford coppola, michael curtiz)
When a name appears two times, it means that the person won 2 oscars and so on. What i need to do is to go trough this list and find every actor that won N or more Oscars, with a predicate like
wonMoreOscars(Number, Activity):-
Where the number is the N we have to compare with the list.
I already have a function that counts the person that occurs the more times in a list and the activity the function that person has in the movie, but is already covered.
Can somebody help me, i have the code to find the person who has won more Oscars:
occS([],_,_,_,_):-write(0),nl,write('+'),nl, !.
occS([H|T],_,_,_,_):-occ([H|T],0,0,H,H).
occ([],_,Top,_,Nome):-write(Nome),nl,write(Top),nl,write('+'),nl, !.
occ([H|T],Count,Top,El_corrente,_):- compare(=,H,El_corrente),C is Count + 1,C>=Top,occ(T,C,C,El_corrente,El_corrente), !.
occ([H|T],_,Top,El_corrente,Nome):- not(compare(=,H,El_corrente)),occ(T,1,Top,H,Nome),!.
occ([H|T],Count,Top,_,Nome):- C is Count + 1,occ(T,C,Top,H,Nome), !.
But now i’m having trouble with this case.
I assume you want to write a predicate that takes a number and a list of actors and returns a list of those that are in the list at least specified-number-times (
wonMoreOscars(Number, Activity)doesn’t have enough parameters). You can do it like this: