开发者

how to fetch all the words which can be formed with the given letters?

consider I've a tables which has all the dictionary words,

I want to fetch the list of words from the db which can be formed with the given set of alphabets..

for this what could be query???..

I thought of fetching every character using substr and comparing whether its present in a list and word length less than or equal to given set of alphabets..

for example

if i give the following set of alphabets,

I , L, S, N, N, E

then i should be able to get the words like th开发者_JAVA百科e following ones,

SIN, NIL, INN, INS, LINEN, LINENS, LINE, SINE, LENS etc.,,

What would be the query?


SELECT * 
  FROM dictionary 
 WHERE word REGEXP '^[ILSNE]{1,6}$';

Not a perfect solution, but it might give you something to work with


There is no way (that I know of) to search for a word in a db formed by a list of letters in mySQL. The easieest way of doing so would be to generate beforehand a list of possible words and selecting from the database these words (pseudo-code):

foreach(word in possible_word_list)
{
    SELECT * FROM dictionary WHERE dictionary.word=word
}

and to generate the possible word list:

function get_possible_word_list(letters_list)
{
    word_list = array();
    foreach(letter in letters_list)
    {
        word_list.add( letter + get_possible_word_list(letters_list.remove(letter));
    }
    return word_list;
}

Or something like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜