Skip to content

Instantly share code, notes, and snippets.

@pzula
Last active December 27, 2015 09:29
Show Gist options
  • Save pzula/7304753 to your computer and use it in GitHub Desktop.
Save pzula/7304753 to your computer and use it in GitHub Desktop.
Hamming in Exercism
class Hamming
attr_accessor :mutation_count
def self.compute(original_dna, mutated_dna)
unless original_dna.length == mutated_dna.length
length_adjuster([original_dna, mutated_dna])
else
@original = original_dna.chars
@mutated = mutated_dna.chars
end
mutation_count
end
def self.length_adjuster(strands)
lengths = strands.sort_by {|strand| strand.length}
shorter_length = lengths[0].length
@original = lengths[0]
@mutated = lengths[1].ljust(shorter_length)
end
def self.mutation_count
count = 0
@original.each_with_index do |acid, index|
unless @original[index] == @mutated[index]
count += 1
end
end
return count
end
end
# 1.
# 1a. Find the shorter of the two
# 1b. gsub the longer of the two to be as short as the other and store that shorter one
# 1c. Take the two inputs and split each string into seperate arrays
# 2. Iterate over both arrays at once
# 3a. Create a counter set to 0
# 3b. When both indicies in the array do not match, up the count
# 4. Return the count in self.compute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment