ruby - hamming (fixes)
use Enumerable.count and unless positive_conditional
This commit is contained in:
parent
9304aca5a2
commit
b800f5729c
@ -1,15 +1,7 @@
|
|||||||
class Hamming
|
class Hamming
|
||||||
def self.compute(a, b)
|
def self.compute(strand_one, strand_two)
|
||||||
if a.length != b.length
|
raise ArgumentError unless strand_one.length == strand_two.length
|
||||||
raise ArgumentError
|
|
||||||
end
|
|
||||||
|
|
||||||
distance = 0
|
0.upto(strand_one.length - 1).count {|i| strand_one[i] != strand_two[i] }
|
||||||
0.upto(a.length - 1) do |i|
|
|
||||||
if a[i] != b[i]
|
|
||||||
distance += 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
distance
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user