Optimal Algorithm for Winning Hangman

后端 未结 7 1369
庸人自扰
庸人自扰 2021-02-04 03:18

In the game Hangman, is it the case that a greedy letter-frequency algorithm is equivalent to a best-chance-of-winning algorithm?

Is there ever a case where it\'s worth

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 04:05

    I have written a script that solves hangman optimally [github].

    My basic strategy is this:

    • For a pattern such as ..e.. with tried letters: e,s,t
    • Check against words of only n digits (in this case 5)
    • Create a list of possible words
      • Create a regex from the supplied info
      • In this case it would be [^est][^est]e[^est][^est]
      • Parse your word list for words that match this regex
    • Cycle through each word, counting up the number of times every letter appears
    • Your optimal next guess is the most likely letter

提交回复
热议问题