From: Logan Capaldo Date: 2005-09-23T14:22:13+09:00 Subject: Re: hi, i'm new. plus one question On Sep 23, 2005, at 12:41 AM, travis laduke wrote: > > On Sep 22, 2005, at 5:00 AM, Brian Schr�der wrote: > > >> On 22/09/05, travis laduke wrote: >> >> >> Hope this helps: >> >> bschroed@black:~/svn/projekte/ruby-things$ cat rotate.rb >> module Rotate >> def rotate(steps = 1) >> steps = steps % self.length >> self[-steps..-1].concat self[0...-steps] >> end >> end >> >> >> regards, >> >> Brian >> >> -- >> http://ruby.brian-schroeder.de/ >> >> Stringed instrument chords: http://chordlist.brian-schroeder.de/ >> >> >> > > > you guys are magicians, thanks > > 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. > > oh, and how to i point ruby to a directory where i want to put all > my modules and such?, or where should i put all my modules and > such? i'm on an apple computer. > > > travis > > > Yeah, thats O(n!) IIRC. What you can try is #!/usr/bin/env ruby my_hand = %w( a b c ) # Only an example, put the letters you actually have here seed = 'br' # Something already on the board you have room to build off # Note, put only the part that would be in your word # eg. if the word is bread, going down and you want to start at the e and go to the right # use only the letter e as your seed File.open('/usr/share/dict/words') do |dictionary| dictionary.grep(/^#{seed}(?:#{my_hand.join('|')})+/) do |word| word.chomp! puts word if (word.split(//) - (seed.split(//) + my_hand)).empty? end end Note that its very, very limited and not smart at all. It'll narrow down your choices somewhat, and may be helpful in a minor way, but its just a heuristic and a poor one at that, not an alogirithm and not all the answers it gives you will be right. Seems like a good Ruby Quiz though, a scrabble bot.