S
S
SerKonRu2017-01-31 17:37:43
Prolog
SerKonRu, 2017-01-31 17:37:43

How does this program work in Prolog?

Given a program in Prolog. Can you please explain how it works?

count(_,[],0).

count(X,[X|L],N):-count(X,L,N2),N is N2 + 1.

count(X,[_|L],N):-count(X,L,N).
p([],_,[]).
p([X|V],N,[X|L]):-count(X,[X|V],K),K >= N, delete(V,X,V2),p(V2,N,L).

p([X|V],N,L):-delete(V,X,V2),p(V2,N,L).

This program removes from the input list all elements that appear in this list more than N times.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question