Created
March 21, 2013 02:52
-
-
Save 1mentat/5210348 to your computer and use it in GitHub Desktop.
Hamming Distance
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 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