#!/usr/bin/env python # # Draw Something or any other puzzle hint script # # Please note that dictonaries needs to be fetched from various places. # # Licence: BSDLike # import glob import re import sys def find_words(word_length, letters): # No special characters allowed reg=re.compile('^[a-zA-Z]{%s}\n$' % word_length) # Build an list of available words word_dict = {} for fname in glob.glob('/home/rvdzwet/Downloads/scowl-7.1/final/english-*'): with open(fname,'r') as f: for word in f: if reg.match(word): word_dict[word.strip().lower()] = True word = range(word_length) def choice(i, letters): """ Recursively process the letters """ for j in range(0,len(letters)): # Make sure not to process the same letter twice if letters[j] in letters[0:j]: continue word[i] = letters[j] if i == word_length - 1: test_word = ''.join(word) if word_dict.has_key(test_word): print test_word else: choice(i+1, letters[:j] + letters[j+1:]) choice(0, letters) if __name__ == '__main__': try: word_length = int(sys.argv[1]) letters = tuple(sys.argv[2]) find_words(word_length, letters) except IndexError: print "Usage: %s " sys.exit(128)