Efficient word scramble algorithm

前端 未结 4 1682
情歌与酒
情歌与酒 2020-12-30 06:13

I\'m looking for an efficient algorithm for scrambling a set of letters into a permutation containing the maximum number of words.

For example, say I am given the li

4条回答
  •  既然无缘
    2020-12-30 06:42

    Here's an idea, inspired by Markov Chains:

    1. Precompute the letter transition probabilities in your dictionary. Create a table with the probability that some letter X is followed by another letter Y, for all letter pairs, based on the words in the dictionary.
    2. Generate permutations by randomly choosing each next letter from the remaining pool of letters, based on the previous letter and the probability table, until all letters are used up. Run this many times.
    3. You can experiment by increasing the "memory" of your transition table - don't look only one letter back, but say 2 or 3. This increases the probability table, but gives you more chance of creating a valid word.

提交回复
热议问题