Last active
November 3, 2016 15:22
-
-
Save lkrych/31a6d155339491c8072516d99b67119f to your computer and use it in GitHub Desktop.
An improved implementation of the Hamming distance
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 | |
| 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