Skip to content

Instantly share code, notes, and snippets.

@avescodes
Created July 15, 2009 00:25
Show Gist options
  • Save avescodes/147341 to your computer and use it in GitHub Desktop.
Save avescodes/147341 to your computer and use it in GitHub Desktop.
def ham_dist(word)
a = SHA1.hexdigest(word).to_i(16)
b = "6cac827bae250971a8b1fb6e2a96676f7a077b60".to_i(16)
(a ^ b).to_s(2).split('').inject(0) {|sum,i| sum + i.to_i }
end
def permute(sentence)
non_space_chars = sentence.scan(/\S/).count
(0...(2**non_space_chars)).each do |mask|
yield apply_mask(sentence,mask)
end
end
def apply_mask(sentence,mask)
i = 0
sentence.gsub(/\S/) do |char|
char = char.swapcase if mask[i] == 1
i += 1
char
end
end
def yield_all_endings(original)
(0...(2**5)).each do |mask|
'a'.upto('zzzzz') do |ending|
# yield something
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment