Skip to content
Create a gist now

Instantly share code, notes, and snippets.

require 'digest/sha1'
class String
def hash
Digest::SHA1.hexdigest self
def bit
"%0160b" % to_i(16)
def distance(word1, word2)
distance = 0 do |char1, char2|
distance += 1 unless char1 == char2
return distance
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
Something went wrong with that request. Please try again.