Skip to content

Instantly share code, notes, and snippets.

@netmask
Created February 5, 2015 01:00
Show Gist options
  • Save netmask/4ab0b27149fce50100fa to your computer and use it in GitHub Desktop.
Save netmask/4ab0b27149fce50100fa to your computer and use it in GitHub Desktop.
def anagrams()
anagrams = {}
words = []
['CASA', 'SACA', 'AMACA'].each do |word|
anagrams[word] = word.chars.sort
end
anagrams.each do |word, anagram|
anagrams.each do |compare_word, compare_anagram|
words << word if anagram == compare_anagram && word != compare_word
end
end
words
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment