Created
February 20, 2010 15:12
-
-
Save ballpointcarrot/309716 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
def word_to_hash(word) | |
primes = { | |
'a' => 2, 'b' => 3, 'c' => 5, 'd' => 7, 'e' => 1, 'f' => 13, 'g' => 17, | |
'h' => 19, 'i' => 23, 'j' => 29, 'k' => 31, 'l' => 37, 'm' => 41, | |
'n' => 43, 'o' => 47, 'p' => 51, 'q' => 53, 'r' => 59, 's' => 61, | |
't' => 67, 'u' => 71, 'v' => 73, 'w' => 79, 'x' => 83, 'y' => 97, | |
'z' => 101 | |
} | |
sum = 1 | |
word.split('').each{|ch| | |
sum *= primes[ch] | |
} | |
sum | |
end | |
dicFile = File.new("dictionary.txt",'r') | |
contents = dicFile.readlines | |
wordlist = Array.new | |
#Wish I could find a better way to do the total count... it's not right. | |
total = 0 | |
contents.each do |line| | |
hash = word_to_hash(line.strip) | |
total += 1 if wordlist.select{|x| x == hash}.size > 0 | |
wordlist.push(hash) | |
end | |
puts total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment