function pos = findPattern(dna,pat)
% Post: pos contains a vector of the positions at which pat appears in dna 
% Pre: Vector dna contains an array of DNA nucleotides.
% pat contains a pattern of nucleotides 


pos= [];  % vector of locations where 'GGT' occurs

lenPat = length(pat); 

for k= 1: length(dna)-lenPat +1
    % Check to see if pat  is the same substring as 
    % dna(k:k+lenPat-1) 
    % We do this in a non vectorized way first 
    i=1; 
    while( i<= lenPat && dna(k+i-1) == pat(i) ) 
      i = i+1; %increment the index i until we find a difference
    end
    
    if (i==lenPat+1)  % all entries coincided
        pos = [pos k]; % add position k to the list 
    end
              
end