Word by Word

Time limit: 0.1s Memory limit: 64MB Input: Output:

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 ss consisting of 55 lowercase letters by using at most 99 guesses.

To make a guess, you need to pick a string gg consisting of 55 lowercase letters. The jury will then give you a string rr consisting of 55 characters, which can be G (green), Y (yellow) or W (white). These colors largely have the following meanings:

  • If rir_i is G (green), then the ii-th letter from your guess is correct (that is, gi=sig_i = s_i).
  • If rir_i is Y (yellow), then the ii-th letter from your guess is incorrect, however it occurs somewhere else in the hidden string (that is, gisig_i \neq s_i and there exists some jij \neq i for which gi=sjg_i = s_j).
  • If rir_i is W (white), then the ii-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 s=s = jazzy and g=g = zyzyz, then rr will be equal to YYGWW:

  • Since g3=s3g_3 = s_3, r3=r_3 = G.
  • Since g1s1g_1 \neq s_1, but g1=s4g_1 = s_4, r1=r_1 = Y.
  • Since g2s2g_2 \neq s_2, but g2=s5g_2 = s_5, r2=r_2 = Y.
  • Since there are no more occurences of y and z in ss to match with g4g_4 and g5g_5, both r4r_4 and r5r_5 are equal to W.

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 11 and 5 0005\ 000 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 (55 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 3030 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 qq be the maximum number of guesses your program needed to guess the hidden string across all test cases for a given test.

  • If q>30q > 30, then you will receive no points for this test.
  • If 26q3026 \leq q \leq 30, then you will receive 10%10 \% of the total number of points for this test.
  • If 12q<2612 \leq q < 26, then you will receive 25%25 \% of the total number of points for this test.
  • If q=11q = 11, then you will receive 40%40 \% of the total number of points for this test.
  • If q=10q = 10, then you will receive 60%60 \% of the total number of points for this test.
  • If q9q \leq 9, 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 with YYGWW.
  • After guessing azzzy, the jury responds with YWGGG.
  • After guessing yazzy, the jury responds with WGGGG.
  • 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, ...

Log in or sign up to be able to send submissions!