source: misc/puzzle-suggestions.py@ 394

Last change on this file since 394 was 366, checked in by Rick van der Zwet, 13 years ago

Draw-Something and all other sometimes needs a little help.

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/env python
2#
3# Draw Something or any other puzzle hint script
4#
5# Please note that dictonaries needs to be fetched from various places.
6#
7# Licence: BSDLike
8#
9import glob
10import re
11import sys
12
13def find_words(word_length, letters):
14 # No special characters allowed
15 reg=re.compile('^[a-zA-Z]{%s}\n$' % word_length)
16
17 # Build an list of available words
18 word_dict = {}
19 for fname in glob.glob('/home/rvdzwet/Downloads/scowl-7.1/final/english-*'):
20 with open(fname,'r') as f:
21 for word in f:
22 if reg.match(word):
23 word_dict[word.strip().lower()] = True
24
25 word = range(word_length)
26 def choice(i, letters):
27 """ Recursively process the letters """
28 for j in range(0,len(letters)):
29 # Make sure not to process the same letter twice
30 if letters[j] in letters[0:j]:
31 continue
32 word[i] = letters[j]
33 if i == word_length - 1:
34 test_word = ''.join(word)
35 if word_dict.has_key(test_word):
36 print test_word
37 else:
38 choice(i+1, letters[:j] + letters[j+1:])
39
40 choice(0, letters)
41
42
43if __name__ == '__main__':
44 try:
45 word_length = int(sys.argv[1])
46 letters = tuple(sys.argv[2])
47 find_words(word_length, letters)
48 except IndexError:
49 print "Usage: %s <length> <letters>"
50 sys.exit(128)
51
Note: See TracBrowser for help on using the repository browser.