Skip to content

Instantly share code, notes, and snippets.

@saevarb
Last active August 29, 2015 14:06
Show Gist options
  • Save saevarb/24812422ae0397400ce1 to your computer and use it in GitHub Desktop.
Save saevarb/24812422ae0397400ce1 to your computer and use it in GitHub Desktop.
% Always zero elements of any element in the empty list
count(_, [], 0).
count(E, L, C) :- count(E, L, C, 0).
% This means that the count of the empty list is simply whatever
% is in the accumulator when the list is empty.
count(_, [], Acc, Acc).
count(E, [X|L], C, Acc) :- count(E, L, C, Acc).
count(X, [X|L], C, Acc) :-
Y is Acc + 1, count(X, L, C, Y).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment