In Wordle, you try to guess a secret word, and some letters in your guess are highlighted to give you hints.
If you guess a letter which matches the letter in the same position in the secret word, the letter will be highlighted green. For example, if the secret word is LEMON
and you guess BEACH
, then the E
will be highlighted green.
If you guess a letter which is present in the secret word, but not in the correct corresponding position, it will be highlighted yellow.
If a letter appears more times in the guess than it does in the secret word, only upto as many occur in the secret may be highlighted. If any of the occurrences are in the same place, they should be preferentially highlighted green, leaving earlier letters unhighlighted if necessary.
For example, with the secret LEMON
and the guess SCOOP
, the second O
will be green, because it is in the right place, but the first O
will be unhighlighted, because there is only one O
in the secret, and one O
has already been highlighted.
Any of the remaining letters in the secret may be highlighted yellow if they match, as long as the right number are highlighted in total. For example, with the secret LEMON
and the guess GOOSE
, only one of the O
s should be highlighted; it does not matter which.
Task
Given two five-letter strings, a secret and a guess, highlight the letters in the guess according to the rules above.
You can "highlight" the letters using any reasonable output format. For example:
- a length-
5
list of highlight values - a list of 5 pairs of
(letter, highlight value)
- a mapping from indices
0
-4
or1
-5
to the highlight at that position
You can choose any three distinct values to represent unhighlighted, yellow, and green. (For example, 0
/1
/-1
, or ""
/"Y"
/"G"
...)
If in doubt about the "reasonable"ness of your output format, please ask. It must be unambiguous about the ordering of highlighting in case of double letters.
Rules
- You may assume the inputs are both of length 5 and contain only ASCII letters
- You may choose whether to accept input in uppercase or lowercase
- You may take input as a string, a list of character codes, or a list of alphabet indices (in \$ [0, 25] \$ or \$ [1, 26] \$)
- You may use any standard I/O method
- Standard loopholes are forbidden
- This is code-golf, so the shortest code in bytes wins
Test cases
All using the secret word HELLO
: \$ \require{color} \newcommand{\qG}[1]{\colorbox{##0f0}{$ \mathtt #1 $}} \newcommand{\qY}[1]{\colorbox{##ff0}{$ \mathtt #1 $}} \newcommand{\qW}[1]{\colorbox{
##eee}{$ \mathtt #1 $}} \$
SCRAP
-> \$ \qW S \qW C \qW R \qW A \qW P \$HELLO
-> \$ \qG H \qG E \qG L \qG L \qG O \$EPOCH
-> \$ \qY E \qW P \qY O \qW C \qY H \$CIVIL
-> \$ \qW C \qW I \qW V \qW I \qY L \$BELCH
-> \$ \qW B \qG E \qG L \qW C \qY H \$ZOOMS
-> \$ \qW Z \qY O \qW O \qW M \qW S \$ or \$ \qW Z \qW O \qY O \qW M \qW S \$LLAMA
-> \$ \qY L \qY L \qW A \qW M \qW A \$EERIE
-> \$ \qW E \qG E \qW R \qW I \qW E \$HALAL
-> \$ \qG H \qW A \qG L \qW A \qY L \$LLLXX
-> \$ \qY L \qW L \qG L \qW X \qW X \$ or \$ \qW L \qY L \qG L \qW X \qW X \$LLLLL
-> \$ \qW L \qW L \qG L \qG L \qW L \$