Skip to content

Instantly share code, notes, and snippets.

@lkrych
Last active November 3, 2016 15:22
Show Gist options
  • Save lkrych/31a6d155339491c8072516d99b67119f to your computer and use it in GitHub Desktop.
Save lkrych/31a6d155339491c8072516d99b67119f to your computer and use it in GitHub Desktop.
An improved implementation of the Hamming distance
class Hamming
def self.compute(s1,s2)
distance = 0
raise ArgumentError if s1.length != s2.length
s1.chars.zip(s2.chars) {|s1char, s2char| distance += 1 unless s1char == s2char}
distance
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment