Created
November 18, 2010 19:38
-
-
Save paveltyk/705476 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
letters = 'satire' | |
dictionary = {} | |
results = [] | |
File.open("/usr/share/dict/words", "r") do |infile| | |
while line = infile.gets | |
word = line.chomp.downcase | |
next if word.size != 7 | |
key = word.chars.sort.join | |
if dictionary.has_key? key | |
dictionary[key] << word | |
else | |
dictionary[key] = [word] | |
end | |
end | |
end | |
('a'..'z').each do |letter| | |
key = (letters + letter).downcase.chars.sort.join | |
results += dictionary[key] if dictionary[key] | |
end | |
results.sort.each { |word| puts word } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment