Created
November 3, 2016 15:17
-
-
Save lkrych/c3dfc3285441f6b8e12567d6e7d3f7a2 to your computer and use it in GitHub Desktop.
Almost the same as Hamming_improved_2.rb
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
| class Hamming | |
| def self.compute(s1,s2) | |
| distance = 0 | |
| if s1.length != s2.length | |
| raise ArgumentError | |
| else | |
| s1.chars.zip(s2.chars) {|s1char, s2char| distance += 1 unless s1char == s2char} | |
| return distance | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment