-
-
Save stevenhao/ff3b465960434239ab97502e7c95a0d8 to your computer and use it in GitHub Desktop.
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
#!/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