Skip to content

Instantly share code, notes, and snippets.

@paveltyk
Created November 18, 2010 19:38
Show Gist options
  • Save paveltyk/705476 to your computer and use it in GitHub Desktop.
Save paveltyk/705476 to your computer and use it in GitHub Desktop.
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