Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sequences in Prolog

Status
Not open for further replies.

jodders

Programmer
Nov 12, 2003
13
0
0
GB
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.

Really need help
 
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]).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top