Python 3, (1, 149, 840945, 12131118, 112102)
from collections import Counter # history: a list of tuple of (guess, feedback) # feedback: a list of length 5, each element can be MISS, CLOSE, or MATCH def play(history): # Hard coded first guess turn = len(history) + 1 if turn == 1: return 'trace' # When there are few words left remaining_words = [word for word in WORDS if all(get_feedback(guess, word) == feedback for guess, feedback in history)] if len(remaining_words) <= 2: return remaining_words[0] # Hardcoded hard case if turn == 3 and history == [('trace', [MISS, CLOSE, MISS, MISS, CLOSE]), ('risen', [CLOSE, MISS, MISS, MATCH, MISS])]: return 'howdy' guess_list = WORDS if turn > 2 and len(remaining_words) < 100 else remaining_words return find_best_guest(guess_list, remaining_words) def find_best_guest(guess_list, secret_list): R = [] secret_set = set(secret_list) for guess in guess_list: c = Counter([tuple(get_feedback(guess, secret)) for secret in secret_list]) R.append([guess, len(c), guess in secret_set, -max(c.values())]) best_guess = max(R, key=lambda t:(t[1],-t[2])t[1:]) return best_guess[0] Each time, I pick the guess from the list of remaining words (words matching all previous guesses), such that the guess splits the words intomaximize the most number of groupspossible outcomes. For example, at the start, we guess "trace". This splits the possible secrets into 150 groups, only one of which is possible based on the feedback. For the second guess, if we guess a word from that group, then there is 1 universe where we guess correctly. Thus in total, we have 150 universes where we guess correctly within the first 2 turns. By maximizing the number of groups each turn, we can make sure that there are more universes where we guess correctly early on.
- If we have too few remaining words, then we might have to guess a word outside of those, to get the best split. Specifically, I allow selecting from outside if we're at the 3rd guess (or after) and there are less than 100 remaining words.
- I brute forced search a some hard subtrees (e.g. 'trace' -> 'risen') to get the worst case at most 5 guesses.