title: Wrong order when performing Naïve Pattern Search - Python
body: <p>I am implementing the Naïve Pattern Search Algorithm in Python, and after running the code, it spits out in the wrong order (right to left). Below is my code:</p>
  <pre><code>def bruteForce(Pattern, Chars):
  #get lengths of pattern and chars
      M = len(Pattern)
      N = len(Chars)
  # go through the Pattern[]
      for i in range(N - M + 1):
          j = 0
      # For current index i, check for pattern match
          while(j &lt; M):
              if (Chars[i + j] != Pattern[j]):
              break
              j = j + 1
  
          if (j == M):
                  print(&quot;Pattern found at index: &quot;, i + j - 1, i)
  
  letters = &quot;abc&quot;
  Chars = ''.join(random.choice(letters) for i in range(1000))
  print(Chars)
  Pattern = &quot;abcba&quot;
  
  def main():
      bruteForce(Pattern, Chars)
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>Sample Output: 106 to 102</p>
  <p>The correct output should be 102 to 106</p>