# returns an array of matching palindromes in the file # the words are grouped in arrays # # [['god','dog'],['act','cat']] # def find_palindromes(file) if !file || !File.exist?(file) || !File.readable?(file) raise "Trouble with the file" end words = File.open(file,"r").read words = words.split(/\s/) words.uniq! palindrome = Hash.new(Array.new) for word in words palpalindrome_word = word,split.sort.join # you can downcase and remove chars here palindrome[palindrome_word] = palindrome[palindrome_word].push(word) end palindrome.values.reject{|words| words.size<2} end