travis laduke <wrong / socal.rr.com> wrote: > > i thought not being able to rotate was the only thing standing in my > way of finding all the anagrams (permutations) of a string so i can > enhance my chances of beating my girlfriend at online scrabble. > turns out its a lot harder than i first imagined. Permutations are not an efficient way to find anagrams, note. Something like this is better (untested): dictfile = 'sowpods.txt' anags = {} IO.foreach(dictfile) {|word| word.chomp! word.upcase! alpha = word.split(//).sort.join('') anags[alpha] ||= [] # set the value to [] if it doesn't exist anags[alpha] << word } puts "Enter rack" rack = gets.chomp.upcase.sort n = rack.length # work through all subracks max = 2**n - 1 max.downto(1) {|i| s = "" 0.upto(n) {|j| s << rack[i] if i[j] == 1 } puts anags[s] } martin