Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: secret code generator

by MonkOfAnotherSect (Sexton)
on Dec 22, 2006 at 11:21 UTC ( #591298=note: print w/ replies, xml ) Need Help??


in reply to secret code generator

</lurk>
His Python code is not terribly pleasant:
1/ there's absolutely no need for an object, much less repeated recursive object creation
2/ The spacing is bizarre (though that might be the fault of your pasting)
3/ (minor nit) self.Outer should be self.outer
4/ His code is slooooow
5/ I consider myself a reasonable Python programmer ;-) but trying to follow that gives me a headache
6/ As others have noted it's rather inflexible Here's a shorter simpler faster more-flexible version plus a test to demonstrate that his version is more than 5** times slower under Py2.5!!:

def make_combos(curr, *rest): if rest: rest = make_combos(*rest) else: rest = [""] for y in rest: for x in curr: yield y + x def password_generator(seeds=DEFAULT_CHAR_SET, minlen=1, maxlen=8): chars = [seeds]*minlen for i in range(minlen, maxlen+1): for elem in make_combos(*chars): yield elem chars.append(seeds) # insert the code for PasswordGenerator here def test_combos(): for pwd in password_generator(): yield pwd def test_generator(): for elem in PasswordGenerator(): yield elem if __name__ == "__main__": for test_type in [test_combos, test_generator]: for i in range(3): test = test_type().next start = time.time() for j in range(1000000): test() # change to "print test()" if you want output print time.time() - start, print
[**To be fair, his version is slightly faster for smaller numbers and gets worse the larger the number of passwords required...]<lurk>


Comment on Re: secret code generator
Download Code
Re^2: secret code generator
by BrowserUk (Pope) on Dec 22, 2006 at 12:03 UTC
    I consider myself a reasonable Python programmer ;-) but trying to follow that gives me a headache

    Phew! And I thought it was just my lack of Python skills, and the repetitive banging of my head on the wall that was the cause :)


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://591298]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-12-22 23:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls