Created
October 18, 2021 20:17
-
-
Save cameronabrams/58b64f389f677941b45c8d75b90f3779 to your computer and use it in GitHub Desktop.
Don't cheat at the New York Times Spelling Bee!
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
''' Cheat at NYT Spelling Bee ''' | |
import random | |
class Words: | |
def __init__(self): | |
with open('/usr/share/dict/words','r') as f: | |
raw=f.read().split('\n') | |
self.words=[w.upper() for w in raw if (not "'" in w and len(w)>3 and w.islower())] | |
self.sevens=[w for w in self.words if (len(w)==7 and len(set(w))==7)] | |
def findbees(self,letters): | |
if len(set(letters))!=7: | |
print('Bad letter set:',letters) | |
return [] | |
res=[] | |
for w in self.words: | |
if letters[0] in w: | |
good=True | |
for l in w: | |
if l not in letters: | |
good=False | |
if good: | |
res.append(w+('*' if len(set(w))==7 else '')) | |
return res | |
if __name__=='__main__': | |
U=Words() | |
for bee in U.findbees('CHEATOR'): | |
print(bee) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment