Skip to content

Instantly share code, notes, and snippets.

@ybur-yug
Created April 9, 2016 23:18
Show Gist options
  • Select an option

  • Save ybur-yug/64c3e7724f242a364e3e33e91b66b8f5 to your computer and use it in GitHub Desktop.

Select an option

Save ybur-yug/64c3e7724f242a364e3e33e91b66b8f5 to your computer and use it in GitHub Desktop.
module Hamming
def compute_hamming_distance string_1, string_2
raise ArgumentError unless strings_like_length? string_1, string_2
string_1.chars.zip(string_2.chars).count { |x, y| x != y }
end
def strings_like_length? a, b
a.length == b.length
end
end
class MyMathyClass
extend Hamming
end
MyMathyClass.new.compute_hamming_distance "abc", "abcde"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment