Wordle is a popular online word game called Wordle. There are instructions given at the official site for Wordle, but essentially, it is a word guessing game. In this game, each guess is marked by indicating which letters of your guess match a secret answer.
A Green mark indicates that you have found a correct letter in the correct position in the secret word. A Yellow mark indicates that you have found a correct letter but in an incorrect position relative to the secret word. A Grey mark indicates that the given letter does not appear in the secret word at all.
Be careful of duplicate letters: a letter that is guessed twice may be marked once as Green or Yellow and once as Grey if there is only a single occurrence of that letter in the secret word. In particular, Green markings take priority over Yellow markings, and Yellow markings have a priority in the guess, reading from Left to Right.
Given the datatypes dataCheck = GreenYellowGrey deriving (Eq, Show, Read), typeMarking = [(Char, Check)], write a function markGuess :: String -> String -> Marking that takes the secret word to be guessed and a guess of the same length. The function should return a marking according to the Wordle rules. The order of the returned marking matters and should satisfy map fst (markGuess secret guess) == guess.
An example marking showing the marking priorities is markGuess “aaabb” “bbxxb” should return [(b, Yellow), (b, Grey), (x, Grey), (x, Grey), (b, Green)]. The final ‘b’ in the guess is marked Green because it is correctly placed in the secret word. The first ‘b’ in the guess is marked Yellow because there is a second occurrence of ‘b’ in the secret word in a different position. The second ‘b’ in the guess is marked Grey because there is no third occurrence of ‘b’ in the secret word.
Note that your solution should work with strings of any length but should report an error where the two given strings are of different lengths.
Hint: A reasonable strategy is to write a helper function that finds the characters marked Green first. Then feed the result of that helper function into another helper function that finds the Yellow markings.