Skip to content

Instantly share code, notes, and snippets.

@slackorama
Last active January 13, 2021 02:08
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 slackorama/f842235329cc99fe4e86593dcd6a1e09 to your computer and use it in GitHub Desktop.
Save slackorama/f842235329cc99fe4e86593dcd6a1e09 to your computer and use it in GitHub Desktop.
Solve the NYT spelling bee. Mind you this isn't perfect.
#!/usr/bin/env python3
import sys
# called via `panagram.py ktocail`
# last letter in the word is required
def get_words(letters):
# prevent dupes
seen = set()
check = set(list(letters))
required = letters[-1]
with open('/usr/share/dict/american-english') as f:
for line in f:
# strip out words with apostrophes
word = line.strip().lower().split("'")[0]
if len(word) >= 4 and word not in seen:
if required in word and set(word).issubset(check):
seen.add(word)
if check == set(word):
print('PANAGRAM ', end='')
print(word)
if __name__ == '__main__':
get_words(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment