-
-
Save ads901119/3070555 to your computer and use it in GitHub Desktop.
Sift3 in Python
This file contains 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 sift3(s1,s2, maxOffset): | |
s1L = len(s1) | |
s2L = len(s2) | |
if not s1: | |
return (not s2 and 0 or s2L) | |
if not s2: | |
return s1L | |
c1 = 0 | |
c2 = 0 | |
lcs = 0 | |
while c1<s1L and c2<s2L: | |
if s1[c1] == s2[c2]: | |
lcs += 1 | |
else: | |
for i in range(1,maxOffset): | |
if c1+i < s1L and s1[c1+i] == s2[c2]: | |
c1 += i | |
break | |
if c2+i < s2L and s1[c1] == s2[c2+i]: | |
c2 += i | |
break | |
c1 += 1 | |
c2 += 1 | |
return ((s1L+s2L)/2-lcs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment