Wordle is a web-based word game created and developed by Welsh software engineer Josh Wardle. Players have six attempts to guess a five-letter word, with feedback given for each guess in the form of coloured tiles indicating when letters match or occupy the correct position. — Wikipedia
Task
In this problem, you will have to find a hidden string consisting of lowercase letters by using at most guesses.
To make a guess, you need to pick a string consisting of lowercase letters. The jury will then give you a string consisting of characters, which can be G
(green), Y
(yellow) or W
(white). These colors largely have the following meanings:
- If is
G
(green), then the -th letter from your guess is correct (that is, ). - If is
Y
(yellow), then the -th letter from your guess is incorrect, however it occurs somewhere else in the hidden string (that is, and there exists some for which ). - If is
W
(white), then the -th letter from your guess is incorrect.
However, if you repeat a letter in your guess more times than it appears in the hidden string, then the excess will be colored in white.
For example, if jazzy
and zyzyz
, then will be equal to YYGWW
:
- Since ,
G
. - Since , but ,
Y
. - Since , but ,
Y
. - Since there are no more occurences of
y
andz
in to match with and , both and are equal toW
.
Interaction protocol
Firstly, you need to include the definitions of the functions which you will use/implement in your program; use #include "word-by-word.h"
.
Please note, you don't need to write any main
function. You instead need to implement the following function:
string solve();
This function will be called by the jury multiple times throught the execution of the program, because each test contains between and test cases.
This function will return the hidden string.
You can make a guess using the following function:
string guess(string g);
If you provide a string that doesn't have the correct format ( lowercase letters), this function will return an empty string.
Constraints and clarifications
- The interactor in this task is not adaptive. In other words, the hidden string is fixed in every test case and does not change during the interaction.
- If your solution uses more than guesses for a particular test case, you will receive the "Wrong answer" verdict.
Scoring
If your program did not solve all test cases correctly for a given test, then you will receive no points for this test.
Otherwise, let be the maximum number of guesses your program needed to guess the hidden string across all test cases for a given test.
- If , then you will receive no points for this test.
- If , then you will receive of the total number of points for this test.
- If , then you will receive of the total number of points for this test.
- If , then you will receive of the total number of points for this test.
- If , then you will receive of the total number of points for this test.
- If , then you will receive the full amount of points for this test.
Example 1
query("aaaaa"); // GGGGG
return "aaaaa";
Explanation
The hidden string is aaaaa
. After guessing aaaaa
, the jury responds with GGGGG
, meaning that every character from the guess is correct. As such, we can submit our answer by returning the string aaaaa
.
Example 2
query("green"); // WWGYW
query("piece"); // WWGGY
query("beech"); // WGGGG
query("leech"); // GGGGG
return "leech";
Explanation
The hidden string is leech
. The interaction for this testcase is depicted in the image from the statement.
Example 3
query("zyzyz"); // YYGWW
query("azzzy"); // YWGGG
query("yazzy"); // WGGGG
return "jazzy";
Explanation
The hidden string is jazzy
.
- After guessing
zyzyz
, the jury responds withYYGWW
. - After guessing
azzzy
, the jury responds withYWGGG
. - After guessing
yazzy
, the jury responds withWGGGG
. - Then, the answer
jazzy
is returned. Note that there are other strings that are also consistent with the responses from the jury, such as:bazzy
,cazzy
,xazzy
, ...