the unix(argv([Word|Constraints])), line makes it look like it's intended to run from the command prompt, instead of in the SWI-Prolog interface. If you replace that with getWord(Word), the program should prompt you for words instead. Then just start up SWI-Prolog, type in['filename.pl']. at the...
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)...
You seem to be missing rules for 3 and 4 cards in a suit. You should assign a value of 0 to those cases. Otherwise, prolog can't unify hands containing those numbers of cards, so it will say 'No'.
General hint: make sure you dig recursion
Hint on previous-to:
It's obviously true if X is the head of a list and Y is a member of the list. So you must first figure out a member predicate, then reduce Z to the point where X is the head.
Hint on number-occurences:
number-occurences(X,[],0)...
You probably want to start with some simpler predicates you can use in constructing the more complex ones, such as:
/ member(X,Ys) returns true if X is a member of Ys
member(X,[X|_Xs]).
member(X,[_Y|Ys]):-member(X,Ys).
/ select(X,Ys,Zs) returns true if Zs is Ys with the first occurence of X...
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.