function result = countPattern2(dna, pat)
% returns the number of substrings in dna that match pat

result = 0;
L1 = length(dna);
L2 = length(pat);

for i = 1:L1-L2+1
    if (sum(dna(i:i+L2-1) ~= pat) == 0) 
        result = result + 1;
    end
end