Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2012 22:16
Show Gist options
  • Save anonymous/1968628 to your computer and use it in GitHub Desktop.
Save anonymous/1968628 to your computer and use it in GitHub Desktop.
def combine_anagrams(words)
word_copy=words.dup;arr=Array.new
words.each{|w| arr<<w.downcase.split(//).sort.join}
p arr
end
string=['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams','scream']
combine_anagrams(string)
OUTPUT:
["acrs", "for", "aeoopstt", "acrs", "foru", "acrs", "acemrs", "acemrs"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment