Created
March 7, 2017 15:46
-
-
Save mcelaney/e915155b423e74e724130461b8879dc9 to your computer and use it in GitHub Desktop.
PhillyDev Slack #Daily_Programmer for March 7, 2016
This file contains 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 HammingDistance | |
def self.hammit(left, right) | |
fail 'lengths don\'t match' if different_lengths?(left, right) | |
(0..compare_length(left, right)).map { |index| | |
left[index] == right[index] | |
}.select { |result| | |
result == false | |
}.count | |
end | |
def self.compare_length(left, _) | |
left.size | |
end | |
def self.different_lengths?(left, right) | |
left.size != right.size | |
end | |
end | |
left = 'GAGCCTACTAACGGGAT' | |
right = 'CATCGTAATGACGGCCT' | |
HammingDistance.hammit(left, right) == 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment