Skip to content

Instantly share code, notes, and snippets.

@1mentat
Created March 21, 2013 02:52
Show Gist options
  • Save 1mentat/5210348 to your computer and use it in GitHub Desktop.
Save 1mentat/5210348 to your computer and use it in GitHub Desktop.
Hamming Distance
def hammingdistance(s1,s2):
distance = 0
for c1,c2 in zip(s1,s2):
xchar = c1 ^ c2
distance += bin(xchar).count('1')
return distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment