Skip to content

Instantly share code, notes, and snippets.

/.rb Secret

Created January 29, 2015 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/da0c403d692d17a14bfa to your computer and use it in GitHub Desktop.
Save anonymous/da0c403d692d17a14bfa to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Exercism 1
# Hamming Test
class Hamming
# Hold 0 in a global var for number of differences
def self.compute(str_1, str_2)
count = 0
if str_1.length == str_2.length
if str_1 == str_2
0
elsif str_1.length == 1
1
elsif str_1.length >= 2
arr_1 = str_1.split('')
arr_2 = str_2.split('')
until arr_1.count == 0 do
if arr_1.pop != arr_2.pop
count += 1
end
end
count
end
else
puts "You have input a sequence of improper length. Aborting."
0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment