On 16/09/12 13:06, aklei...@sonic.net wrote:

#!/usr/bin/env python

# file :  every.py
print 'Running "every.py"'

possible = "234567abcdefghijklmnopqrstuvwxyz"
word_length = 16

word_list = []
def add_word(word):
     if len(word)==word_length:
         word_list.append(word)
         print word   # There may come a time you won't want this line.
     else:
         for c in possible:
             new_word = word + c
             add_word(new_word)

add_word("")

# print word_list
[...]
There won't be any whitespace or commas in any of the derived output.
For your purposes, you might want to make this into a generator although
that would be getting too sophisticated for me to help you.
Since in its present form the algorithm is a recursive one, I'm guessing
it'll run out of memory long before it comes to completion although I
haven't let it run for more than a few seconds,

There are 32**16 = 1208925819614629174706176 16-character strings using
digits 2-7 and lowercase a-z. To store a full list of them all will take
at least 74953400816107 terrabytes of memory. Given that even high-end
IBM Blade servers don't support even a single terrabyte of RAM, I think
that your guess about running out of memory is pretty safe...




--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to