Random word from giving letter
Is there any possible 开发者_运维知识库code for getting output in php(all possible word from word dictionary)
for example....for word "werflo"
flower
fowler
reflow
wolfer
- Take your word list, order each word's letters (alphebetical or otherwise, as long as it's consistent).
- Associate each word with its ordered letter string
- Apply the same letter ordering to your input
- Find the matching words, which is now trivial as you just need to find those where the ordered letter sequence matches.
I don't know PHP, but you could
- pre-sort all the words in the dictionary, remembering their original position (for example, "flower" will be stored as "eflorw"); sort the dictionary lexocographically;
- sort the letters in your input word the same way;
- with binary search find the sorted word within the sorted dictionary;
- by the stored index, find the original words in the original dictionary.
精彩评论