as the title, says, I need to write a program that finds three equal and consecutive values from a List, eg:
find([o,o,a,b,b,b,c,c], X)
X = [b,b,b].
My day to day is functional programming, but I'm struggling a bit with what my program is doing because it never output concrete results (eg: outputs X = [_7714,_7720,_7726])
The program I did is the following:
find(_List, X) :-
length(X, Size),
Size = 3,
format('X = ~w', [X]).
find([Equal, Equal|Tail], X) :-
is_list(X),
append([Equal, Equal], X, Y),
find([Equal|Tail], Y).
find([Equal, Equal|Tail], _X) :-
append([Equal, Equal], [], Y),
find([Equal|Tail], Y).
find([_Equal, Diferent|Tail], _X) :-
find([Diferent|Tail], []).
What Am I missing here or what Am I confusing in prolog theory. For me, my program makes sense, I can't really understand where the code is being executed in each step (even using trace.).
Any help is totally appreciated! Thanks in advance!