Code covered by the BSD License  

Highlights from
Text Twist Puzzle Solver

from Text Twist Puzzle Solver by Khaled Hamed
Gives the solution of a Text Twist Puzzle

tt(str)
function tt(str)
%TT get the solution of a Text Twist puzzle.
%
%   TT(STR) lists all possible meaningful words (according to Microsoft 
%   Word dictionary) resulting from different combinations of the letters 
%   in input string STR.
%
%   Example:
%   tt('sttaes')  or tt sttaes
%
%       Solution:
%           states
%           tastes
%           asset
%             .
%             .
%             .
%           tat
%           tea
%
%   Copyright 2009 K. Hamed

%Open MS Word
Doc = actxserver('Word.Application');

%Check all possible combinations for valid words
aa='';
for i=3:length(str);
    w=nchoosek(1:length(str),i);
    for u=1:size(w,1)
        x=str(w(u,:));
        k=perms(1:i);
        for j=1:size(k,1);
            st=x(k(j,:));
            status=invoke(Doc,'CheckSpelling',st,[],1,1);
            if status==1;
                aa=char(aa,st);
            end;
        end;
    end;
end;

%Close MS Word
invoke(Doc,'Quit');
delete(Doc);

%Remove repeated words (occurs when a given letter is repeated in STR)
aa=unique(cellstr(aa));

%Sort words according to their length
for i=1:length(aa);
    r(i)=length(aa{i});
end;
[x i]=sort(-r);
aa=aa(i);

%Display solution
fprintf('\nSolution:\n');
for i=1:length(aa);
    fprintf('%s\n',aa{i});
end;

Contact us at files@mathworks.com