adwiz
adwiz

Reputation: 21

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"

  1. flower

  2. fowler

  3. reflow

  4. wolfer

Upvotes: 2

Views: 375

Answers (2)

Vlad
Vlad

Reputation: 35594

I don't know PHP, but you could

  1. pre-sort all the words in the dictionary, remembering their original position (for example, "flower" will be stored as "eflorw"); sort the dictionary lexocographically;
  2. sort the letters in your input word the same way;
  3. with binary search find the sorted word within the sorted dictionary;
  4. by the stored index, find the original words in the original dictionary.

Upvotes: 3

Joey
Joey

Reputation: 354496

  1. Take your word list, order each word's letters (alphebetical or otherwise, as long as it's consistent).
  2. Associate each word with its ordered letter string
  3. Apply the same letter ordering to your input
  4. Find the matching words, which is now trivial as you just need to find those where the ordered letter sequence matches.

Upvotes: 6

Related Questions