Skip to content

Instantly share code, notes, and snippets.

@Rocketknight1
Created January 23, 2022 12:33
Show Gist options
  • Save Rocketknight1/1ef384b17cc3034a2159ecef3658bad3 to your computer and use it in GitHub Desktop.
Save Rocketknight1/1ef384b17cc3034a2159ecef3658bad3 to your computer and use it in GitHub Desktop.
from collections import Counter
words = [word.strip() for word in open("wordle-answers-alphabetical.txt").readlines() if word.strip()]
allowed_words = [word.strip() for word in open("wordle-allowed-guesses.txt").readlines() if word.strip()]
allowed_words = list(set(allowed_words) | set(words))
def compare_guess(guess, answer):
answer = list(answer)
output = ['X' for _ in range(len(answer))]
for i, letter in enumerate(guess):
if answer[i] == letter:
output[i] = 'G'
answer[i] = None
for i, letter in enumerate(guess):
if output[i] == 'G':
continue
if letter in answer:
output[i] = 'Y'
answer[answer.index(letter)] = None
return ''.join(output)
while True:
scores = dict()
for guess in allowed_words:
outputs = Counter([compare_guess(guess, true_word) for true_word in words])
scores[guess] = sum(val**2 for val in outputs.values())
best_guess = [key for key in scores if scores[key] == min(scores.values())][0]
best_distribution = Counter([compare_guess(best_guess, true_word) for true_word in words])
print("Next guess: ", best_guess)
result = input("Input result as X/Y/G: ").strip().upper()
words = [word for word in words if compare_guess(best_guess, word) == result]
print(len(words), " options remaining")
if len(words) <= 4:
print("Few remaining options: ")
print(words)
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment