I want to implement a predicate even_sequence(X,Y,Z) where X is the given list, Y is a counter of the max length of even numbers sequence, and Z is the counter that stores the length of the current even number subsequence. For example for the given list 2,4,6,3,5,2,2 i want to return 3 because 2,4,6 is the longest sequence.
Here is the code that i tried and i don't know how to make it work(i am a total beginner in Prolog).If i run even_sequence([2,2,2,3,3],C,R) i get the error: Arguments are not sufficiently instantiated In: [1] even_sequence([2,2|...],_1730,_1732)
even_sequence([],_,_).
even_sequence([H|T],GlobalMax,LocalMax):-
H mod 2 =:= 0,
LocalMax1 is LocalMax+1,
even_sequence(T,GlobalMax,LocalMax1).
even_sequence([H|T],GlobalMax,LocalMax):-
H mod 2 =\= 0,
GlobalMax1 is LocalMax,
LocalMax1 is LocalMax-LocalMax,
even_sequence(T,GlobalMax1,LocalMax1).