Skip to content

Instantly share code, notes, and snippets.

@stevenhao
Last active June 10, 2016 19:41
Show Gist options
  • Save stevenhao/ff3b465960434239ab97502e7c95a0d8 to your computer and use it in GitHub Desktop.
Save stevenhao/ff3b465960434239ab97502e7c95a0d8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
def cut(lst):
return lst[:5]
with open("words") as f:
all_words = f.read().split("\n")
common = filter(lambda word: all(c.islower() for c in word), all_words)
fours = filter(lambda s: len(s)==4, common)
from collections import defaultdict
def msk(mask, word):
return ''.join('_' if m == '1' else c for c, m in zip(word, mask))
masks = ['']
for i in range(4):
masks = map(lambda w: w + '0', masks) + map(lambda w: w + '1', masks)
clues = defaultdict(list)
for word in fours:
for mask in masks:
clue = msk(mask, word)
clues[clue].append(word)
a, b = clues['n___'], clues['_n__']
print cut(a), len(a)
print cut(b), len(b)
clues = list(clues.iteritems())
clues.sort(key=lambda (clue,lst): len(lst), reverse=True)
for clue,lst in cut(clues):
print clue, cut(lst), len(lst)
#update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment