You are playing Hangman, and your opponent uses a simple but effective strategy: Each turn, from the remaining letters, they guess the letter that appears most frequently across all possible words. When multiple letters appear with the same maximum frequency, your opponent selects randomly among them.
That is, your opponent knows which dictionary (list of words) you've chosen your word from, and has computed a table showing how many times each letter of the alphabet appears in this dictionary. Your opponent always chooses letters with higher frequency counts before letters with lower frequency counts.
Your goal is to write a program that will select a word that maximizes their average number of guesses.
This is code golf.
Input / Output
The input will be a list of words in any convenient format, per standard site IO rules (comma delimited string, array, lines of a file, etc).
The output will be a single word from that list that maximizes your opponent's average number of guesses. If there is more than one such word, you may return any one of them.
If the input word list is:
one wont tee
The letter frequency table will be:
┌─┬─┬─┬─┬─┐ │e│t│o│n│w│ ├─┼─┼─┼─┼─┤ │3│2│2│2│1│ └─┴─┴─┴─┴─┘
Your opponent will always guess
e first, since it occurs most frequently. Their second, third, and fourth guesses will be split randomly among the letters
w will always be guessed last.
Thus the word
wont will always be completed last, on the 5th guess, and is the sole correct answer for this word list.
- Words will contain only the 26 letters
- If you want, you can use the uppercase alphabet instead.
- When there is more than one correct answer, you may return any of them. If you want, you can return all of them, but this is not required.
Each test case consists of two lines:
- An input word list of space-separated words.
- The expected output. This will be a single word when there is only one correct answer, and a space-separated list when there is more than one. Note that your program only needs to return one correct answer when there are multiple correct answers.
one wont tee wont aaa bbb ccc aaa bbb ccc oneword oneword thee lee thee tee lee tee lee three eon one holt three holt xeon threes eon one holt threes xeon threes eon one holt apple mango george any fine fine