Implement a program to solve a Wordle-style word guessing game. The game has a hidden target word of fixed length L (e.g.,
5) drawn from a known dictionary. After each guess, you receive per-character feedback: Correct (right letter, right position), Present (letter exists but different position), or Absent (letter not in the word). Requirements:
(
-
Keep guessing until the word is solved or a maximum attempt limit is reached;
(
-
Design data structures and an algorithm to maintain constraints and prune the candidate set after each feedback;
(
-
Correctly handle repeated letters and seemingly conflicting feedback (e.g., one instance Present while another is Absent);
(
-
Propose and implement a strategy to choose the next guess (e.g., frequency-based heuristic or information-gain approximation) and justify it;
(
-
Provide an interface solve(dictionary, feedback_api, max_attempts) -> (final_guess, num_attempts) where feedback_api(guess) returns the feedback for each position;
(
-
Analyze time and space complexity;
(
-
Include unit tests and demonstrate a sample run.