Created
July 14, 2009 21:42
-
-
Save brainopia/147217 to your computer and use it in GitHub Desktop.
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment