Changeset aee143254881…
Parent 0c352cff9833…
by
Changes to one file · Browse files at aee143254881 Showing diff from parent 0c352cff9833 Diff from another changeset...
@@ -1,3 +1,4 @@ + import functools
import sys
@@ -35,7 +36,15 @@ return s[0] in self._letters and s[1:] in self._letters[s[0]]
-def solve(board, forbidden):
+def word_weight(word, favor):
+ score = 0
+ for c in favor:
+ if c in word:
+ score += 3
+ return score + len(word)
+
+
+def solve(board, favor, forbidden):
def find_words(board, word, trie):
words = set()
if trie.is_terminal():
@@ -51,19 +60,18 @@ print ' 0 words loaded',
for i, l in enumerate(open('wordlist', 'r')):
word = l.strip()
- if word not in forbidden:
- if i % 10 == 0:
- print '\r %s words loaded' % (i,),
- t.add(word)
+ if i % 100 == 0:
+ print '\r %s words loaded' % (i,),
+ t.add(word)
print '\r %s words loaded\n' % (i + 1,)
print 'SEARCHING'
- print ' 0 words found',
- words = sorted(find_words(board, '', t), key=lambda x: len(x), reverse=True)
- print '\r %s words found\n' % len(words)
+ score = functools.partial(word_weight, favor=favor)
+ words = sorted((w for w in find_words(board, '', t) if w not in forbidden), key=lambda x: score(x), reverse=True)
+ print ' %s words found\n' % len(words)
print 'BEST WORDS:'
for word in words[:10]:
print ' %s' % word
if __name__ == '__main__':
- solve(sys.argv[1], sys.argv[2:])
+ solve(sys.argv[1], sys.argv[2], set(sys.argv[3:]))
|
Loading...