Last active
August 29, 2015 14:06
-
-
Save saevarb/24812422ae0397400ce1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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