Last active
December 17, 2015 23:19
-
-
Save lrhazi/5688651 to your computer and use it in GitHub Desktop.
Cheat for game "4 Pics 1 Word". run with two arguments, length of word and string of possible letters. It finds a list of possible english words, using /usr/share/dict/words list of words.
This file contains 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
import re,sys | |
from itertools import permutations | |
def getDict(length): | |
filename = "/usr/share/dict/words" | |
words = set(x.strip().upper() for x in open(filename) if len(x.strip()) == length) | |
return words | |
if __name__ == "__main__": | |
if len(sys.argv) != 3: | |
sys.exit(1) | |
length = int(sys.argv[1]) | |
letters = sys.argv[2] | |
words = getDict(length) | |
print("Loaded %d words of length %d"%(len(words),length)) | |
found = set() | |
for w in ["".join(x).upper() for x in permutations(letters, length)]: | |
if w in words: | |
found.add(w) | |
print("Found %d words."%len(found)) | |
print(" ".join(sorted(found))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment