Created
September 9, 2013 15:34
-
-
Save alekst/6497278 to your computer and use it in GitHub Desktop.
a code to find the number of different links in two strands of DNA. Done for exercism.io.
This file contains 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 DNATest < MiniTest::Unit::TestCase | |
class DNA | |
def initialize(strand) #initializes the original strand | |
@strand = strand | |
end | |
def hamming_distance(sample) # compares it to sample | |
0 if sample.empty? # returns 0 if sample DNA is empty | |
@strand = split(@strand) # splits the orginal DNA strand into an array | |
sample = split(sample) # splits the sample DNA strand into an array | |
@strand = @strand.take(sample.length) # if the original strand is longer, ignores the rest of the strand | |
@strand.each_with_index.count{|item, index| item != sample[index]} # returns number of different elements | |
end | |
def split(string) | |
string.split('') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment