Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
Created June 20, 2012 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perspectivezoom/2962900 to your computer and use it in GitHub Desktop.
Save perspectivezoom/2962900 to your computer and use it in GitHub Desktop.
module Anagram
attr_reader :word_dict
def anagrams
@word_dict = {}
self.each do |str|
puts str
sorted_str = str.chars.sort.join
if @word_dict[sorted_str] == nil
@word_dict[sorted_str] = [str]
else
@word_dict[sorted_str] << str
end
end
end
end
class Array
include Anagram
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment