0
votes

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.

1
you should show your code and the problem you're facing...CapelliC

1 Answers

1
votes

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).