I need help with sequences where you can have a sequence of three letters eg. R,G,B in any order. The only two problems are letters are not allowed twice in sucession and G,B,R is not allowed in sucession.
Assuming you're representing the sequences as lists of r,g, and b (since prolog interprets capitals as variables), and you want to accept an empty sequence, you want something like:
gbr(g,b,r).
accept([]).
accept([X]).
accept([X,Y]):-X /== Y.
accept([X,Y,Z|Xs]):-
X /== Y,
not gbr(X,Y,Z),
accept([Y,Z|Xs]).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.