Sometimes when you're playing Wordle, you get to your fifth guess and you can't figure out the word any more, so you start mentally running through the list of remaining iterations, both sensical and nonsensical trying to figure out what those last few letters are.
The task here is to create all permutations of a final Wordle guess to save me from having to do it in my head, with the following rules:
General rules:
- Wordle rules apply (similar to codebreaker game).
- Guess an unknown five-letter word.
- Guesses will return an indication of whether the letter is in the word such that:
- If a letter is in the correct position, it will be green
- If a letter appears in the word but is not in the correct position, it will be yellow
- If a letter does not appear in the word, it will be black.
- Letters can appear more than once in the solution (provided the solution is still a valid word)
- If a letter is guessed twice in the same guess (such as "guess") but is in the correct word fewer times than guessed, only the number of the repeated letters will be green or yellow. If the position is correct for one of the placements, that will appear green, regardless of the position in the sequence. If the positions are all wrong, the earliest occurence/s will be marked yellow and the following one/s black.
- Inputs should be solvable, even if no solutions are "real" words.
- Since Wordle only uses valid English words, only letters that appear on a standard English keyboard (a-z) need to be tested. However, you should include all valid permutations, not just valid English words, in your output.
- Solution is case insensitive.
Input:
- A list of letters and indices (0 or 1 indexed, your choice), indicating the location of confirmed/green letters - indicate the index you chose;
- A list of letters and indices (consistently indexed), indicating yellow letters (i.e. the letter is known to not be at that index);
- A list/string of letters that are yet to be guessed.
Note, green and yellow letters may still appear in more than the known positions. For example, if the input for green is [('E', 1)]
, there may still be an E
in an index other than 1
as well.
Output:
All potential "words" of exactly 5 letters, such that the green letters are in the indicated indexes, the yellow letters are not in the indicated indexes (but must appear at least once in the output), and the words consist of only the green, yellow, and remaining letters. The output may be in any order.
What's the shortest way to solve this problem? You may take input and output in any convenient method or format, and the shortest code in bytes wins.
Example:
- Green Guesses (1 indexed): O=2, E=4, N=5
- Yellow Guesses: N!=3 (E!=5 is excluded because we know N=5)
- Unguessed Letters: Q, W, I, P, F, J, K, X, B
All other letters (A, C, D, F, G, H, L, M, R, S, T, U, V, Y, Z) have been guessed and cannot occur in the result.
Output would be a list of all possible permutations given the known information, such as:
["BOBEN", "BOEEN", "BOFEN", "BOIEN", "BOJEN", "BOKEN", "BOOEN", "BOPEN", "BOQEN", "BOWEN", "BOXEN", "EOBEN", "EOEEN", "EOFEN", "EOIEN", "EOJEN", "EOKEN", "EOOEN", "EOPEN", "EOQEN", "EOWEN", "EOXEN", "FOBEN", "FOEEN", "FOFEN", "FOIEN", "FOJEN", "FOKEN", "FOOEN", "FOPEN", "FOQEN", "FOWEN", "FOXEN", "IOBEN", "IOEEN", "IOFEN", "IOIEN", "IOJEN", "IOKEN", "IOOEN", "IOPEN", "IOQEN", "IOWEN", "IOXEN", "JOBEN", "JOEEN", "JOFEN", "JOIEN", "JOJEN", "JOKEN", "JOOEN", "JOPEN", "JOQEN", "JOWEN", "JOXEN", "KOBEN", "KOEEN", "KOFEN", "KOIEN", "KOJEN", "KOKEN", "KOOEN", "KOPEN", "KOQEN", "KOWEN", "KOXEN", "NOBEN", "NOEEN", "NOFEN", "NOIEN", "NOJEN", "NOKEN", "NOOEN", "NOPEN", "NOQEN", "NOWEN", "NOXEN", "OOBEN", "OOEEN", "OOFEN", "OOIEN", "OOJEN", "OOKEN", "OOOEN", "OOPEN", "OOQEN", "OOWEN", "OOXEN", "POBEN", "POEEN", "POFEN", "POIEN", "POJEN", "POKEN", "POOEN", "POPEN", "POQEN", "POWEN", "POXEN", "QOBEN", "QOEEN", "QOFEN", "QOIEN", "QOJEN", "QOKEN", "QOOEN", "QOPEN", "QOQEN", "QOWEN", "QOXEN", "WOBEN", "WOEEN", "WOFEN", "WOIEN", "WOJEN", "WOKEN", "WOOEN", "WOPEN", "WOQEN", "WOWEN", "WOXEN", "XOBEN", "XOEEN", "XOFEN", "XOIEN", "XOJEN", "XOKEN", "XOOEN", "XOPEN", "XOQEN", "XOWEN", "XOXEN"]
Output may be in any order.
In this case:
- There are 12 possibilities for the first letter (any of "BEFIJKNOPQWX")
- There is 1 possibility for the second letter ("O")
- There are 11 possibilities for the third letter (any of "BEFIJKOPQWX", excluding N)
- There is 1 possibility for the fourth letter ("E")
- There is 1 possibility for the fifth letter ("N")
So the result should contain a total of 12 * 1 * 11 * 1 * 1 = 132 items.
In code terms, the inputs may be given as:
[['O', 2], ['E', 4], ['N', 5]]
or[["O", "E", "N"], [2, 4, 5]]
or similar[['N', 3]]
or[["N"], [3]]
or similar"QWIPFJKXB"
or["Q","W","I","P","F","J","K","X","B"]
or similar
and the output as:
['BOBEN', 'EOBEN', 'FOBEN', 'IOBEN', 'JOBEN', 'KOBEN', 'NOBEN', 'OOBEN', 'POBEN', 'QOBEN', 'WOBEN', 'XOBEN', 'BOEEN', 'EOEEN', 'FOEEN', 'IOEEN', 'JOEEN', 'KOEEN', 'NOEEN', 'OOEEN', 'POEEN', 'QOEEN', 'WOEEN', 'XOEEN', 'BOFEN', 'EOFEN', 'FOFEN', 'IOFEN', 'JOFEN', 'KOFEN', 'NOFEN', 'OOFEN', 'POFEN', 'QOFEN', 'WOFEN', 'XOFEN', 'BOIEN', 'EOIEN', 'FOIEN', 'IOIEN', 'JOIEN', 'KOIEN', 'NOIEN', 'OOIEN', 'POIEN', 'QOIEN', 'WOIEN', 'XOIEN', 'BOJEN', 'EOJEN', 'FOJEN', 'IOJEN', 'JOJEN', 'KOJEN', 'NOJEN', 'OOJEN', 'POJEN', 'QOJEN', 'WOJEN', 'XOJEN', 'BOKEN', 'EOKEN', 'FOKEN', 'IOKEN', 'JOKEN', 'KOKEN', 'NOKEN', 'OOKEN', 'POKEN', 'QOKEN', 'WOKEN', 'XOKEN', 'BOOEN', 'EOOEN', 'FOOEN', 'IOOEN', 'JOOEN', 'KOOEN', 'NOOEN', 'OOOEN', 'POOEN', 'QOOEN', 'WOOEN', 'XOOEN', 'BOPEN', 'EOPEN', 'FOPEN', 'IOPEN', 'JOPEN', 'KOPEN', 'NOPEN', 'OOPEN', 'POPEN', 'QOPEN', 'WOPEN', 'XOPEN', 'BOQEN', 'EOQEN', 'FOQEN', 'IOQEN', 'JOQEN', 'KOQEN', 'NOQEN', 'OOQEN', 'POQEN', 'QOQEN', 'WOQEN', 'XOQEN', 'BOWEN', 'EOWEN', 'FOWEN', 'IOWEN', 'JOWEN', 'KOWEN', 'NOWEN', 'OOWEN', 'POWEN', 'QOWEN', 'WOWEN', 'XOWEN', 'BOXEN', 'EOXEN', 'FOXEN', 'IOXEN', 'JOXEN', 'KOXEN', 'NOXEN', 'OOXEN', 'POXEN', 'QOXEN', 'WOXEN', 'XOXEN']
E
s and a yellowE
in any position other than the empty one would result in just the one "word" in the output, but could never occur when playing the game. This scenario seems harmless, but I'm not sure if other ones might be weird, yet. \$\endgroup\$["","B","","U","T"] ["O","","A","",""] ["Q","W","I","P","F","J","K","X"]
should produce the single word "ABOUT". \$\endgroup\$