Public » Letterpress
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

now with working

Changeset be6e15c36b75

Parent b1be9d887ae9

by Benjamin Pollack

Changes to one file · Browse files at be6e15c36b75 Showing diff from parent b1be9d887ae9 Diff from another changeset...

Change 1 of 1 Show Entire File solver.py Stacked
 
40
41
42
 
 
43
44
45
 
 
 
46
47
48
49
 
 
 
50
51
 
 
52
 
53
54
55
56
 
 
 
 
 
 
 
57
58
59
 
40
41
42
43
44
45
 
 
46
47
48
49
50
51
 
52
53
54
55
56
57
58
59
60
61
 
 
 
62
63
64
65
66
67
68
69
70
71
@@ -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:])