public
Last active

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
require 'digest/sha1'
 
class String
def hash
Digest::SHA1.hexdigest self
end
def bit
"%0160b" % to_i(16)
end
end
 
def distance(word1, word2)
distance = 0
word1.chars.zip(word2.chars) do |char1, char2|
distance += 1 unless char1 == char2
end
return distance
end
 
test_phrase = "Rubinius one eight six active active record memcached exception JRuby DHH TOKYO sdfe3"
key_phrase = "I am not a big believer in fortune telling"
 
h1 = test_phrase.hash
h2 = key_phrase.hash
 
b1 = h1.bit
b2 = h2.bit
 
p distance b1, b2 # => 74

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.