Skip to content

Instantly share code, notes, and snippets.

@altamic
Created August 31, 2011 17:22
Show Gist options
  • Save altamic/1184114 to your computer and use it in GitHub Desktop.
Save altamic/1184114 to your computer and use it in GitHub Desktop.
words = Hash.new
File.open("dictionary.txt", "r") do |file|
while line = file.gets
word = line.chomp
words[word.split('').sort!.join('')] += [word]
end
end
loop do
print "Enter a word: "
anagram = gets.chomp
sorted_anagram = anagram.split('').sort!.join('')
p words[sorted_anagram]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment