-1

With a list containing only 0 and 1, it is required to find out whether each occurance of [0, 1] is followed (not necessarily immediately) by an occurance of [1, 0, 0]. How to do that?

hola
  • 930
  • 1
  • 17
  • 35

1 Answers1

1

Instead of defining an automa, you could use a builtin, and the search capability of Prolog.

append/3 establish a relation among 3 lists. Namely, the third list is the concatenation of the first two. This can be used to answer easily your assignment:

satisfy(L) :- append(_, [0,1|R], L), append(_, [1,0,0|_], R).

as you can see, append(_, PatternAndRest, L) search the pattern in L and yields the Rest.

But you are probably required to write a recursive predicate that scan the list looking for pattern. I hope the syntax you can see in satisfy/1 will help you.

CapelliC
  • 59,646
  • 5
  • 47
  • 90