Created
May 3, 2016 00:36
-
-
Save wwalker/19adbfb5dfad48af9cfb6e1066e8b92c 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
class Hamming | |
def self.compute(a, b) | |
[a, b].min.size.times.count { | |
|i| a[i] != b[i] | |
} | |
end | |
end | |
class Hamming | |
def self.compute(a, b) | |
# select the shorter strand | |
c = [a, b].min | |
length = c.size | |
# length.times returns an iterator that will return 0, 1, 2, ...length -1 | |
# count takes each element of an array and runs the block, | |
# keeping count of the nunmber of times the block returns true | |
# so this returns the number of strand matches. | |
length.times.count { |i| | |
a[i] != b[i] | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment