Guess the Wordle

View as PDF

Submit solution

Points: 10
Time limit: 2.0s
Memory limit: 128M

Author:
Problem types

Wordle is a game where you are given 6 tries to guess a 5 letter word. After each guess, you are given a series of hints that indicate which letters you have guessed correctly.

A hint will clarify the following for every letter of your guess:

  • If a letter is not in the word, it will turn gray.
  • If a letter is in the word but in the wrong spot, it will turn yellow.
  • If a letter is in the word and in the right spot, it will turn green.


You are to implement a program that takes in a list of N distinct words of length K and repeatedly attempts to guess what the secret word is until it succeeds (the secret word is guaranteed to appear in the list).

For each guess, you will receive input indicating a hint. In the example shown above, a hint for the guess later will be la--*, where - represents gray letters and * represents yellow letters.

Any revealed hints must be strictly used in subsequent guesses (similar to Wordle's hard mode). For example, if a hint indicates that a certain letter cannot appear in the word, then you are not allowed to guess any words containing that letter. Your submission will be correct as long as each subsequent guess does not contradict any of the previous hints provided.

Note: just like regular Wordle, if a letter appears twice in the guess, but that letter only appears once in the secret word, one of the letters will be highlighted gray (e.g. if the secret word was lore and the guess was roll, the hint will be *o*-).

Constraints

2 \le N \le 10^5

2 \le K \le 100

Input Specification

The first line of input contains two integers N and K.

The next N lines of input each contain K lowercase letters.

The rest of the problem is interactive: input will be given based on the guesses you output.

If your guess is correct, the input will be correct!. If your guess contradicts any hints, the input will be wrong!. Otherwise, the input will be K characters that consist of lowercase letters, - and *.

Output Specification

You can make at most up to N guesses.

For each guess, you must output any word from the list that satisfies all of the hints provided, followed by a newline.

After each guess, you must flush your output.

Sample Interaction

Lines preceded by >>> represent your output. Do not output >>>.

4 6
create
wordle
sample
simple
>>> create
---*-e
>>> sample
correct!

Explanation for Sample

Given the hint ---*-e after arbitrarily guessing create, we can deduce that the secret word must contain the letter a; therefore, it cannot be wordle or simple.


Comments

There are no comments at the moment.