Skip to content

Instantly share code, notes, and snippets.

@lrhazi
Last active December 17, 2015 23:19
Show Gist options
  • Save lrhazi/5688651 to your computer and use it in GitHub Desktop.
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.
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