I am trying to learn Prolog and I've been doing some exercises.
There is a list with student's names. Write the predicate filter(L,LN)
that returns a second list named LN
which includes the names like this:
?- filter([kostas, dimitris, anna, antonis, antonia], LN).
LN = [kostas, anna, antonia]
So..it shows one and then skips one and does this continuously. This is what I've done but it isn't correct.
filter([],[]).
filter([H|T],[H|LN]) :-
filter(T,LN,0).
filter([H|T],[H|LN],C) :-
0 is C mod 2,
append(H,LN),
C = C + 1,
filter(T,LN,C).
filter([H|T],LN,C) :-
(C/2) \= 0,
C = C + 1,
filter(T,LN,C).