Skip to content

Instantly share code, notes, and snippets.

@AjayAjaal
Last active December 12, 2015 02:34
Show Gist options
  • Save AjayAjaal/22fd62b3f1b8e11ec106 to your computer and use it in GitHub Desktop.
Save AjayAjaal/22fd62b3f1b8e11ec106 to your computer and use it in GitHub Desktop.
Pattern Matching Algorithms
def naive(pattern, text):
occurrences = []
for i in range(len(text) - len(pattern) + 1):
match = True
for k in range(len(pattern)):
if text[i+k] != pattern[k]:
match = False
break
if match:
occurrences.append(i)
return occurrences
print naive('word', 'There would have been a time for such a word')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment