Created
September 15, 2015 05:51
-
-
Save rishi93/2fe8de93713c4edb0aea to your computer and use it in GitHub Desktop.
Naive Pattern Searching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(string,pattern): | |
string_len = len(string) | |
pattern_len = len(pattern) | |
for i in range(0,string_len - pattern_len + 1): | |
for j in range(0,pattern_len): | |
if string[i+j] != pattern[j]: | |
break | |
if j == pattern_len - 1: | |
print("Pattern found at index",i) | |
print(search("thepatternishere","pattern")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment