<p>What would be the best strategy to generate anagrams.</p>

<blockquote>
<pre><code>An anagram is a type of word play, the result of rearranging the letters
of a word or phrase to produce a new  word or phrase, using all the original
letters exactly once; 
ex.
</code></pre>
  
  <ul>
  <li><strong>Eleven plus two</strong> is anagram of <strong><em>Twelve plus one</em></strong> </li>
  <li><strong>A decimal point</strong> is anagram of <strong><em>I'm a dot in place</em></strong></li>
  <li><strong>Astronomers</strong> is anagram of <strong><em>Moon starers</em></strong></li>
  </ul>
</blockquote>

<p>At first it looks straightforwardly simple, just to jumble the letters and generate all possible combinations. But what would be the efficient approach to generate only the words in dictionary.</p>

<p>I came across this page, <a href="http://lojic.com/blog/2007/10/22/solving-anagrams-in-ruby/" rel="noreferrer">Solving anagrams in Ruby</a>. </p>

<p>But what are your ideas?</p>

Off the top of my head, the solution that makes the most sense would be to pick a letter out of the input string randomly and filter the dictionary based on words that start with that.  Then pick another, filter on the second letter, etc.  In addition, filter out words that can't be made with the remaining text.  Then when you hit the end of a word, insert a space and start it over with the remaining letters.  You might also restrict words based on word type (e.g. you wouldn't have two verbs next to each other, you wouldn't have two articles next to each other, etc).