Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions hamming.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Hamming
def self.compute(strand_1, strand_2, distance = 0)
raise ArgumentError if strand_1.length != strand_2.length

return distance if strand_1.length == 0

unless strand_1[0] == strand_2[0]
distance += 1
end

unless strand_1.length == 1
return Hamming.compute(strand_1[1..-1], strand_2[1..-1], distance)
end

return distance

end
end