When given some input list, I want to build a new list and it should:
- Always add h in front of the new list
- Compare every two consecutive elements of the input list, and, if they are equal, append y to the new list, if not, append x.
Example:
?- control([a,a,b,b],R).
R = [h,y,x,y].
Here is my code so far:
control([H,H|T],K,[K,0|T2]):- control([H|T],[K,0],T2).
control([H,J|T],K,[K,1|T2]):- control([J|T],[K,1],T2).
control([H],G,G).
But it is not working correctly.
?- control([a,a,b,b],[h],L).
L = [[h], 0, [[h], 0], 1, [[[h], 0], 1], 0, [[[...]|...], 1], 0] ;
L = [[h], 0, [[h], 0], 1, [[[h], 0], 1], 1, [[[...]|...], 1], 1] ;
L = [[h], 1, [[h], 1], 1, [[[h], 1], 1], 0, [[[...]|...], 1], 0] ;
L = [[h], 1, [[h], 1], 1, [[[h], 1], 1], 1, [[[...]|...], 1], 1] ;
false.
How can I make it correct?