Last active
January 12, 2022 08:48
-
-
Save floe/95e367acc087758f10c0f2864e4cedc5 to your computer and use it in GitHub Desktop.
Analyse 5-letter words for optimum Wordle guess
This file contains hidden or 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
#!/usr/bin/python3 | |
# cf. https://en.wikipedia.org/wiki/Letter_frequency | |
letters = "EARIOTNSLCUDPMHGBFYWKVXZJQ".lower() | |
#letters = "etaoinshrdlcumwfgypbvkjxqz" | |
words = { } | |
def skip_double(word): | |
pos = 1 | |
for letter in word: | |
if letter in word[pos:]: | |
return True | |
pos = pos+1 | |
return False | |
def get_score(word): | |
score = 0 | |
for letter in word: | |
tmp = letters.find(letter) | |
score += tmp | |
return score | |
with open("/usr/share/dict/british-english","r") as wordlist: | |
for word in wordlist: | |
word = word.strip() | |
if len(word) != 5 or "'" in word or "é" in word or word[0].isupper() or skip_double(word): | |
continue | |
score = get_score(word) | |
if score > 15: | |
continue | |
words[word] = score | |
# cf. https://stackoverflow.com/a/68105488/838719 | |
words = { k:v for k,v in sorted(words.items(), key=lambda x:x[1]) } | |
print("Suggested guesses (lower is better):",words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment