Skip to content

Instantly share code, notes, and snippets.

@fjorgemota
Created July 7, 2012 19:41
Show Gist options
  • Save fjorgemota/3067867 to your computer and use it in GitHub Desktop.
Save fjorgemota/3067867 to your computer and use it in GitHub Desktop.
Sift3 in Python
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