Problem description: Given a list $A=\{1,2,0,7,0,-1,2,6,\ldots\}$ and a list $B=\{0,7,0\}$ write a program that determines whether $B$ appears in $A$ or not. Note: the order of $B$'s items does matter.
Functional way:
MemberQ[Partition[A, 3, 1], B]
The disadvantage of this way is that the whole list $A$ is processed even if $B$ is in the very start of $A$. Compare with the following code which terminates early if $B$ is found in $A$:
Procedural way:
found = False;
L = Length@A;
For[i = 1, i <= (L - 2) && !found, i++,
found = Take[A, {i, i + 2}] == B]
Question: Is there a functional way of solving the problem that does not need to scan/process all of $A$'s elements ?
P.S. Feel free to edit the title.
a = {1, 2, 3, 4}; b = {2, 3, 4}; MatchQ[a, {___, PatternSequence @@ b, ___}]
A Boyer-Moore type alg should be better $\endgroup$