Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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>

In reply to Re: secret code generator by MonkOfAnotherSect
in thread secret code generator by xiaoyafeng

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [GotToBTru]: many times i've been told I made a real hash of thiings
    [GotToBTru]: so .. perhaps it should b e
    [thepkd]: Just wondering why $aohoaoh[0]->{'foo '}[0]->{'bar'} would be difficult to read and understand?
    [thepkd]: I am a noob and find it easier
    [thepkd]: I mean with the branching clearly defined
    [GotToBTru]: what is clear and what is not can be personal
    [LanX]: actually you can skip the arrows in between and it will still work
    [choroba]: -> between curlies and square brackets is optional

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (10)
    As of 2016-12-06 13:55 GMT
    Find Nodes?
      Voting Booth?
      On a regular basis, I'm most likely to spy upon:

      Results (105 votes). Check out past polls.