Possible Duplicate:
How to find list of possible words from a letter matrix [Boggle Solver]
i am making a puzzle solver. So far i am doing all permutations of the word, but there are a lot! for a 12-letter word there are 479001600 perms... The game is a 16 letter puzzle (4x4)
[A][B][C][D]
[E][F][G][H]
[I][J][K][L]
[M][N][X][O]
A word can be made only with the letters that are around the selected letter. What i mean is that for example i cannot select the word AIM because I is not around A... But i can create the word "AFI". You select A then F(is diag. of A) and then I
My code for permutes is
function permute( $tmp, $word, $level )
{
if ( strlen( $word ) > 2)
{
$this->display( $word );
//return ;
}
for ( $i = 0 ; $i < $this->original_word_length ; $i++ )
{
if ( $this->bOne_bond == true and $this->bonds[$level] != -1 and $i != $this->bonds[$level] and $level < $this->max_bonds ) continue ;
if ( strcmp( $tmp{$i}, "N" ) == 0 )
{
$word_tmp = $word ;
$word_tmp .= $this->original_word{$i};
$flags_tmp = $tmp ;
$flags_tmp{$i} = "Y";
$this->permute( $flags_tmp, $word_tmp, $level+1 );
}
}
}
How can i make my calculations based on neighboring letters?
EDIT: the solution is here. Thanks