Changeset be6e15c36b75…
Parent b1be9d887ae9…
by
Changes to one file · Browse files at be6e15c36b75 Showing diff from parent b1be9d887ae9 Diff from another changeset...
@@ -40,20 +40,32 @@ words = set()
if trie.is_terminal():
words.add(word)
+ if len(words) % 10 == 0:
+ print ' %r words found' % len(words),
for i in xrange(len(board)):
- if trie.has_prefix(board[i]):
- words.update(find_words(board[:i] + board[i + 1:], word + board[i], trie))
+ c = board[i]
+ if trie.has_prefix(c):
+ words.update(find_words(board[:i] + board[i + 1:], word + c, trie.subtrie(c)))
return words
t = Trie()
- for l in open('wordlist', 'r'):
+ print 'BUILDING WORD LIST'
+ 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)
+ print '\r %s words loaded\n' % (i + 1,)
- return 'BEST WORDS'
- for word in sorted(find_words(board, '', t), key=lambda x: len(x), reverse=True)[:10]:
- print ' %s' % word
+ 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)
+ print 'BEST WORDS:'
+ for word in words[:10]:
+ print ' %s' % word
if __name__ == '__main__':
solve(sys.argv[1], sys.argv[2:])
|
Loading...