Skip to content

Instantly share code, notes, and snippets.

@femto113
Created August 5, 2022 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save femto113/9f7d761266e045a2d23ce7ac50247140 to your computer and use it in GitHub Desktop.
Save femto113/9f7d761266e045a2d23ce7ac50247140 to your computer and use it in GitHub Desktop.
five five-letter words with twenty-five unique letters
# this expects to be run in a directory with a file named "words" with one valid word per line
# for testing I used one found here:
# https://github.com/tabatkins/wordle-list
# On a 2022 MacBook Air this takes about 15 minutes to process
def pick(rack, words):
used_letters = set("".join(rack))
if len(used_letters) > 20:
print(" ".join(rack))
return
bag = [word for word in words if not any(letter in word for letter in used_letters)]
while bag:
pick(rack + [bag.pop()], bag)
allwords = [line.strip() for line in open("words")]
print("there are", len(allwords), "total valid guesses")
# filter out any words with repeated letters
valid = [word for word in allwords if len(set(word)) == len(word)]
print("there are", len(valid), "valid guesses excluding repeated letters")
# only keep one of each anagram
valid = { "".join(sorted(word)): word for word in valid }.values()
print("there are", len(valid), "valid guesses after keeping just one of each anagram")
pick([], valid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment