Skip to content

Instantly share code, notes, and snippets.

@ka8725
Created August 15, 2013 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ka8725/6242120 to your computer and use it in GitHub Desktop.
Save ka8725/6242120 to your computer and use it in GitHub Desktop.
def to_h(w)
r = {}
w.each_char do |ch|
r[ch] ||= 0
r[ch] += 1
end
r
end
@dict_word_letters = {}
f = File.open('wl.txt')
f.each_line do |word|
word = word.strip
@dict_word_letters[word] = to_h(word)
end
def anagrams(w)
res = []
wh = to_h(w)
@dict_word_letters.each do |w, h|
res << w if wh == h
end
res
end
puts anagrams('horse')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment