Reputation: 55
I'm trying to write a procedure in prolog where a list might look something like this:
threeInRow(x,[b, b, a, threeInRow(x,[b, d, a,
c, a, b, c, d, b,
a, d, d]) b, d, a])
Both of these would return true. The list always contains 9 elements and can be any of character ranging from a-d.
threeInRow(x,[b, b, j
c, j, b,
j, d, d])
Would however return false, because it's not a character ranging from a-d.
Upvotes: 0
Views: 100
Reputation: 1965
If you want to verify only length of the list (9) and allowed elements:
item_allowed(Item) :-
member(Item, [a, b, c, d]).
threeInRow(List) :-
length(List, 9),
maplist(item_allowed, List).
Upvotes: 1