title: How to find list of possible words from a letter matrix [Boggle Solver]
body: <p>Lately I have been playing a game on my iPhone called Scramble. Some of you may know this game as Boggle. Essentially, when the game starts you get a matrix of letters like so:</p>
  <pre><code>F X I E
  A M L O
  E W B X
  A S T U
  </code></pre>
  <p>The goal of the game is to find as many words as you can that can be formed by chaining letters together. You can start with any letter, and all the letters that surround it are fair game, and then once you move on to the next letter, all the letters that surround that letter are fair game, <strong>except for any previously used letters</strong>. So in the grid above, for example, I could come up with the words <code>LOB</code>, <code>TUX</code>, <code>SEA</code>, <code>FAME</code>, etc. Words must be at least 3 characters, and no more than NxN characters, which would be 16 in this game but can vary in some implementations.  While this game is fun and addictive, I am apparently not very good at it and I wanted to cheat a little bit by making a program that would give me the best possible words (the longer the word the more points you get).</p>
  <p><a href="https://i.stack.imgur.com/qLLPp.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/qLLPp.gif" alt="Sample Boggle" /></a><br />
  <sub>(source: <a href="http://www.boggled.org/sample.gif" rel="noreferrer">boggled.org</a>)</sub></p>
  <p>I am, unfortunately, not very good with algorithms or their efficiencies and so forth. My first attempt uses a dictionary <a href="http://www.freebsd.org/cgi/cvsweb.cgi/src/share/dict/web2?rev=1.12;content-type=text%2Fplain" rel="noreferrer">such as this one</a> (~2.3MB) and does a linear search trying to match combinations with dictionary entries. This takes a <em>very</em> long time to find the possible words, and since you only get 2 minutes per round, it is simply not adequate.</p>
  <p>I am interested to see if any Stackoverflowers can come up with more efficient solutions. I am mostly looking for solutions using the Big 3 Ps: Python, PHP, and Perl, although anything with Java or C++ is cool too, since speed is essential.</p>
  <p><strong>CURRENT SOLUTIONS</strong>:</p>
  <ul>
  <li>Adam Rosenfield, Python, ~20s</li>
  <li>John Fouhy, Python, ~3s</li>
  <li>Kent Fredric, Perl, ~1s</li>
  <li>Darius Bacon, Python, ~1s</li>
  <li>rvarcher, VB.NET, ~1s</li>
  <li>Paolo Bergantino, PHP <a href="http://www.rootspot.com/stackoverflow/boggle.php" rel="noreferrer">(live link)</a>, ~5s (~2s locally)</li>
  </ul>