2018-09-21 09:30:10 -04:00
|
|
|
class Hamming
|
2018-09-26 11:54:14 -04:00
|
|
|
class StrandLengthError < ArgumentError
|
|
|
|
def initialize(msg='Strand lengths are not the same size.')
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.compute(strand1, strand2)
|
|
|
|
raise StrandLengthError unless strand1.length == strand2.length
|
2018-09-21 09:30:10 -04:00
|
|
|
|
2018-09-26 11:54:14 -04:00
|
|
|
nucleotide_pairs = strand1.chars.zip(strand2.chars)
|
|
|
|
nucleotide_pairs.count {|n1, n2| n1 != n2}
|
2018-09-21 09:30:10 -04:00
|
|
|
end
|
|
|
|
end
|