Skip to content

Instantly share code, notes, and snippets.

@adamhunter
Created July 16, 2009 12:59
Show Gist options
  • Save adamhunter/148394 to your computer and use it in GitHub Desktop.
Save adamhunter/148394 to your computer and use it in GitHub Desktop.
def hamming_distance(a, b)
dist = 0
val = a ^ b
while !val.zero?
dist += 1
val &= val - 1
end
dist
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment