Created
April 9, 2016 23:18
-
-
Save ybur-yug/64c3e7724f242a364e3e33e91b66b8f5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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