Last active
May 9, 2022 19:11
-
-
Save barrysmyth/32cdd3a538cb533b24a1393a4c758586 to your computer and use it in GitHub Desktop.
A outline Wordle simulator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def play_wordle(target, words, v): | |
""" | |
Play Wordle for a given target word. | |
Args: | |
target: the target word. | |
words: the words available as guesses. | |
v: the vocabulary setting. | |
Returns: | |
guesses: a list of guesses used to identify target otherwise None. | |
""" | |
remaining = words # The remaining guesses. | |
guesses = [] # The guesses so far. | |
constraints = {} # The constraints so far. | |
# While there are some remaining guesses... | |
while len(remaining): | |
# Pick a new guess from the remaining words given the | |
# current constraints and vocabulary setting. | |
guess = pick_guess(remaining, constraints, v) | |
remaining.remove(guess) # Remove the new guess from the remaining words. | |
guesses.append(guess) # Add the new guess to the list of guesses | |
# Update the constraints based on the new guess and target. | |
constraints = update_constraints(constraints, guess, target) | |
# If the new guess matches the target then success. return the guesses. | |
if guess == target: return guesses | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment