Write a predicate called count(X, L, N) that is true if and only if item X occurs exactly N times in list L. For example: count(spam, [oh, spam, spam, we, love, spam), N). % user query N-3; % prolog replies. We type ; to ask if there's any more false % nope, no more! count(X, Coh, spam, spam, we, love, spam), N). % user query X = oh, N = 1; % any more? X-spam, N = 3; % any more? X = we, = 1; % any more? x = love, N = 1; % any more? N = 0. There's a good chance that your code will report more options, including that "spam" occurs 3 times but also twice and also once. That's an error and it's likely due to the order in which things appear. This is a good opportunity to think carefully about why order matters. By the way, the "N=0" is fine, but it's OK if your code also doesn't produce this. % some "nice" prolog settings... :- set_prolog_flag( prompt_alternatives_on, groundness ). : - set prolog_flag(toplevel_print_options, [quoted(true), portray(true), attributes (portray), max_depth(999), priority (699)]). : - set_prolog_flag(answer_write_options, [quoted(true), portray(true), attributes (portray), max_depth(999), priority (699)]). % We start you with some starter code, which handles the case of an empty list. %%%%%%%%% % STARTER % %%%%%%%%%%% count(_, 0, 0). The empty list contains no occurrences of X Finish writing the code for the other two cases. % YOU DO % count(X, [X Rest), N) :- fail. count(X, Y| Rest), N) :- fail. Write a predicate called count(X, L, N) that is true if and only if item X occurs exactly N times in list L. For example: count(spam, [oh, spam, spam, we, love, spam), N). % user query N-3; % prolog replies. We type ; to ask if there's any more false % nope, no more! count(X, Coh, spam, spam, we, love, spam), N). % user query X = oh, N = 1; % any more? X-spam, N = 3; % any more? X = we, = 1; % any more? x = love, N = 1; % any more? N = 0. There's a good chance that your code will report more options, including that "spam" occurs 3 times but also twice and also once. That's an error and it's likely due to the order in which things appear. This is a good opportunity to think carefully about why order matters. By the way, the "N=0" is fine, but it's OK if your code also doesn't produce this. % some "nice" prolog settings... :- set_prolog_flag( prompt_alternatives_on, groundness ). : - set prolog_flag(toplevel_print_options, [quoted(true), portray(true), attributes (portray), max_depth(999), priority (699)]). : - set_prolog_flag(answer_write_options, [quoted(true), portray(true), attributes (portray), max_depth(999), priority (699)]). % We start you with some starter code, which handles the case of an empty list. %%%%%%%%% % STARTER % %%%%%%%%%%% count(_, 0, 0). The empty list contains no occurrences of X Finish writing the code for the other two cases. % YOU DO % count(X, [X Rest), N) :- fail. count(X, Y| Rest), N) :- fail