Skip to content

Commit

Permalink
[ruby][hamming] start from scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofnds committed Jan 9, 2020
1 parent 11f9709 commit 7c6faea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 60 deletions.
29 changes: 4 additions & 25 deletions ruby/hamming/hamming.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
require_relative 'strand'

class Hamming
class SequenceLengthError < ArgumentError; end

def self.compute(sequence1, sequence2)
strand1 = Strand.new(sequence1.chars)
strand2 = Strand.new(sequence2.chars)

new(strand1, strand2).distance
end

def distance
sequence1.zip(sequence2).count { |m1, m2| m1 != m2 }
end

private

attr_reader :sequence1, :sequence2

def initialize(sequence1, sequence2)
unless sequence1.length == sequence2.length
raise SequenceLengthError, 'sequences must have the same length'
end
def self.compute(strand1, strand2)
raise ArgumentError unless strand1.length == strand2.length
raise ArgumentError if (strand1 + strand2) =~ /^[ACTG]$/

@sequence1 = sequence1
@sequence2 = sequence2
strand1.chars.zip(strand2.chars).count { |n1, n2| n1 != n2 }
end
end
35 changes: 0 additions & 35 deletions ruby/hamming/strand.rb

This file was deleted.

0 comments on commit 7c6faea

Please sign in to comment.