Optimal Algorithm for Winning Hangman

后端 未结 7 1384
庸人自扰
庸人自扰 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 03:50

    The answer clearly shows why the greedy algorithm is not the best, but doesn't answer how much better we can get if we stray from the greedy path.

    If we assume all words are equally likely in case you are playing against a computer opponent. The case of 4 letters, 6 lives case if you have option to look simply the second most popular letter your probability of winning increases from 55.2% to 58.2%, if you are willing to check one more letter then it increases to 59.1%.

    Code: https://gist.github.com/anitasv/c9b7cedba324ec852e470c3011187dfc

    A full analysis using ENABLE1 (scrabble dictionary which has 172820 words) with 2 to 6 letters, and with 0 to 10 lives, and 1-greedy to 4-greedy gives the following results. Of course at 25 lives every strategy is equivalent with 100% win rate, so not going beyond 10 lives. Going more than 4-greedy was improving probability only slightly.

    letters, lives, 1-greedy, 2-greedy, 3-greedy, 4-greedy
    
    
    2 letters 0 lives   3.1%    3.1%    3.1%    3.1%
    2 letters 1 lives   7.2%    7.2%    7.2%    8.3%
    2 letters 2 lives   13.5%   13.5%   13.5%   14.5%
    2 letters 3 lives   21.8%   21.8%   22.9%   22.9%
    2 letters 4 lives   32.2%   33.3%   33.3%   33.3%
    2 letters 5 lives   45.8%   45.8%   45.8%   45.8%
    2 letters 6 lives   57.2%   57.2%   57.2%   57.2%
    2 letters 7 lives   67.7%   67.7%   67.7%   67.7%
    2 letters 8 lives   76%     76%     76%     76%
    2 letters 9 lives   84.3%   84.3%   84.3%   84.3%
    2 letters 10 lives  90.6%   91.6%   91.6%   91.6%
    
    
    3 letters 0 lives   0.9%    1.1%    1.1%    1.1%
    3 letters 1 lives   3.4%    3.8%    3.9%    3.9%
    3 letters 2 lives   7.6%    8.4%    8.6%    8.8%
    3 letters 3 lives   13.7%   15%     15.1%   15.2%
    3 letters 4 lives   21.6%   22.8%   23.3%   23.5%
    3 letters 5 lives   30.3%   32.3%   32.8%   32.8%
    3 letters 6 lives   40.5%   42%     42.3%   42.5%
    3 letters 7 lives   50.2%   51.4%   51.8%   51.9%
    3 letters 8 lives   59.6%   60.9%   61.1%   61.3%
    3 letters 9 lives   68.7%   69.8%   70.4%   70.5%
    3 letters 10 lives  77%     78.3%   78.9%   79.2%
    
    
    4 letters 0 lives   0.8%    1%      1.1%    1.1%
    4 letters 1 lives   3.7%    4.3%    4.4%    4.5%
    4 letters 2 lives   9.1%    10.2%   10.6%   10.7%
    4 letters 3 lives   18%     19.4%   20.1%   20.3%
    4 letters 4 lives   29.6%   31.3%   32.1%   32.3%
    4 letters 5 lives   42.2%   44.8%   45.6%   45.7%
    4 letters 6 lives   55.2%   58.2%   59.1%   59.2%
    4 letters 7 lives   68%     70.4%   71.1%   71.2%
    4 letters 8 lives   78%     80.2%   81%     81.1%
    4 letters 9 lives   85.9%   87.8%   88.4%   88.7%
    4 letters 10 lives  92.1%   93.3%   93.8%   93.9%
    
    
    5 letters 0 lives   1.5%    1.8%    1.9%    1.9%
    5 letters 1 lives   6.1%    7.5%    7.9%    8%
    5 letters 2 lives   15.9%   18.3%   18.9%   19.2%
    5 letters 3 lives   30.1%   34.1%   34.8%   34.9%
    5 letters 4 lives   47.7%   51.5%   52.3%   52.5%
    5 letters 5 lives   64.3%   67.4%   68.3%   68.5%
    5 letters 6 lives   77.6%   80.2%   80.6%   80.8%
    5 letters 7 lives   86.9%   88.6%   89.2%   89.4%
    5 letters 8 lives   92.8%   94.1%   94.4%   94.5%
    5 letters 9 lives   96.4%   97.1%   97.3%   97.3%
    5 letters 10 lives  98.2%   98.6%   98.8%   98.8%
    
    
    6 letters 0 lives   3.2%    3.7%    3.9%    3.9%
    6 letters 1 lives   12.6%   14.3%   14.9%   15%
    6 letters 2 lives   29.2%   32.2%   32.8%   33%
    6 letters 3 lives   50.1%   53.4%   54.2%   54.4%
    6 letters 4 lives   69.2%   72.4%   73.1%   73.2%
    6 letters 5 lives   83.1%   85.5%   85.9%   86.1%
    6 letters 6 lives   91.5%   92.9%   93.2%   93.2%
    6 letters 7 lives   95.8%   96.5%   96.7%   96.8%
    6 letters 8 lives   97.9%   98.3%   98.4%   98.5%
    ...
    

提交回复
热议问题