Let's say that we have a dictionary of about 250.000 words. Algorithm should take in 12 letters as an array or a string and find the permutation (or is it variation or combination?) that matches longest word from a dictionary. So, it is not a real permutation, as not all of the letters are used.
Of course, one can always brute-force it, but I wonder what would be the most elegant way to do this?
Answers using languages other than PHP will also be accepted if they do not use any language-specific functions as a shortcut for the main problem.
Note: Words are stored in the database, but I could pull them into memory for speed. Although I'm not sure PHP's indexing is better than that of an MySQL database?