I tried to minimize the number of comparisons between elements. The obvious approach would be to compare the match pattern with each of the four 3-length substrings of the sample, with each substring comparison being processed one element at a time from left to right, for a total of 12 comparisons per sample. We can improve the average case by moving to the next 3-length substring for the first negative comparison, but the worst case is still 12 comparisons (e.g. AAF in AAAAAA). However, if the first two atoms in the match pattern are different, the worst case is only 9 comparisons. An optimization can then be made if the first two atoms in the match pattern are the same, because we can avoid some redundant comparisons. This brings the worst case down to 9 comparisons. Of course, an additional comparison between the first two atoms of the match pattern needs to be carried out to differentiate between the two cases, but this needs to be done only once.