Problem with algorithm

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul McGuire

    #16
    Re: Problem with algorithm

    On Apr 13, 10:22 am, Michael Bentley <mich...@jedimi ndworks.com>
    wrote:
    On Apr 13, 2007, at 9:19 AM, Paul McGuire wrote:
    >
    If you just expand the length to five million* or so, one of those
    strings will contain all the works of Shakespeare.
    >
    Not likely, even with a tiny sampling of the works of Shakespeare:
    >
    # :-)
    >
    import string
    import random
    >
    def main(bardText, maxTries=500000 0):
    tries = 0
    while tries < maxTries:
    tries += 1
    attempt = []
    for letter in bardText.lower( ):
    if random.choice(
    string.lowercas e[:26]
    + string.punctuat ion
    + ' '
    ) == letter:
    attempt.append( letter)
    else:
    break
    if len(attempt) >= 4:
    print '%d: %s' % (
    tries,
    ''.join(attempt )
    )
    >
    if __name__ == "__main__":
    main("Alas, poor Yorick!")
    5000000 << infinity

    Keep tryin'!

    Also, the OP's technique was not doing random string permutations, but
    generating an exhaustive list of all possible sequences from aaa... to
    zzz... . So I think the works of Shakespeare are *bound* to be in
    there somewhere.

    For proof, here's an extract from my sample code from running this
    exhaustive program with length=14:

    ....
    ALASPOORYORICG
    ALASPOORYORICH
    ALASPOORYORICI
    ALASPOORYORICJ
    ALASPOORYORICK
    ALASPOORYORICL
    ALASPOORYORICM
    ALASPOORYORICN
    ALASPOORYORICO
    ....

    -- Paul
    :) (too late for April 1, unfortunately)

    Comment

    • Carsten Haese

      #17
      Re: Problem with algorithm

      On Fri, 2007-04-13 at 10:22 -0500, Michael Bentley wrote:
      On Apr 13, 2007, at 9:19 AM, Paul McGuire wrote:
      >
      If you just expand the length to five million* or so, one of those
      strings will contain all the works of Shakespeare.
      >
      Not likely, even with a tiny sampling of the works of Shakespeare:
      Actually, the OP seems to be interested in generating *all* strings of
      length N. If you generate the set of *all* strings of 5 million
      characters length, at least one of them will contain all works of
      Shakespeare. That statement is utterly true and utterly impractical,
      which is, of course, the point of Paul's joke.

      -Carsten

      Comment

      • Paul McGuire

        #18
        Re: Problem with algorithm

        On Apr 13, 10:49 am, Carsten Haese <cars...@uniqsy s.comwrote:
        On Fri, 2007-04-13 at 10:22 -0500, Michael Bentley wrote:
        On Apr 13, 2007, at 9:19 AM, Paul McGuire wrote:
        >
        If you just expand the length to five million* or so, one of those
        strings will contain all the works of Shakespeare.
        >
        Not likely, even with a tiny sampling of the works of Shakespeare:
        >
        Actually, the OP seems to be interested in generating *all* strings of
        length N. If you generate the set of *all* strings of 5 million
        characters length, at least one of them will contain all works of
        Shakespeare. That statement is utterly true and utterly impractical,
        which is, of course, the point of Paul's joke.
        >
        -Carsten
        But even random typing will *eventually* get there (where "eventually "
        = several gazillion times the age of the universe) - see
        http://en.wikipedia.org/wiki/Infinite_monkey_theorem.

        -- Paul
        If I see farther, it is because I stand on the shoulders of an
        infinite number of monkeys.



        Comment

        • Paul McGuire

          #19
          Re: Problem with algorithm

          On Apr 13, 8:53 am, Steve Holden <s...@holdenweb .comwrote:
          >
          I'm pretty sure you could give a separate name to each atom ont he known
          universe with a scheme like this. Do you really need 20-byte strings?
          >
          Steve,

          Based on the Wikipedia article's estimate of 10**79 atoms in the
          observable universe (is that all?), we would need a string of about 57
          characters long to give each one a separate name.

          (And I'll bet you've typed on an old Royal or two in your time...)

          -- Paul


          Comment

          • Paul McGuire

            #20
            Re: Problem with algorithm

            On Apr 13, 10:41 am, "Paul McGuire" <p...@austin.rr .comwrote:
            On Apr 13, 10:22 am, Michael Bentley <mich...@jedimi ndworks.com>
            wrote:
            >
            >
            >
            >
            >
            On Apr 13, 2007, at 9:19 AM, Paul McGuire wrote:
            >
            If you just expand the length to five million* or so, one of those
            strings will contain all the works of Shakespeare.
            >
            Not likely, even with a tiny sampling of the works of Shakespeare:
            >
            # :-)
            >
            import string
            import random
            >
            def main(bardText, maxTries=500000 0):
            tries = 0
            while tries < maxTries:
            tries += 1
            attempt = []
            for letter in bardText.lower( ):
            if random.choice(
            string.lowercas e[:26]
            + string.punctuat ion
            + ' '
            ) == letter:
            attempt.append( letter)
            else:
            break
            if len(attempt) >= 4:
            print '%d: %s' % (
            tries,
            ''.join(attempt )
            )
            >
            if __name__ == "__main__":
            main("Alas, poor Yorick!")
            >
            5000000 << infinity
            >
            Keep tryin'!
            >
            Also, the OP's technique was not doing random string permutations, but
            generating an exhaustive list of all possible sequences from aaa... to
            zzz... . So I think the works of Shakespeare are *bound* to be in
            there somewhere.
            >
            For proof, here's an extract from my sample code from running this
            exhaustive program with length=14:
            >
            ...
            ALASPOORYORICG
            ALASPOORYORICH
            ALASPOORYORICI
            ALASPOORYORICJ
            ALASPOORYORICK
            ALASPOORYORICL
            ALASPOORYORICM
            ALASPOORYORICN
            ALASPOORYORICO
            ...
            >
            -- Paul
            :) (too late for April 1, unfortunately)- Hide quoted text -
            >
            - Show quoted text -
            And apologies to the OP for beating a dead horse into the ground.

            -- Paul

            Comment

            • Steve Holden

              #21
              Re: Problem with algorithm

              Paul McGuire wrote:
              On Apr 13, 8:53 am, Steve Holden <s...@holdenweb .comwrote:
              >I'm pretty sure you could give a separate name to each atom ont he known
              >universe with a scheme like this. Do you really need 20-byte strings?
              >>
              >
              Steve,
              >
              Based on the Wikipedia article's estimate of 10**79 atoms in the
              observable universe (is that all?), we would need a string of about 57
              characters long to give each one a separate name.
              >
              >>10 ** 79 26 ** 20
              True
              >>>
              Well, we can't be right all the time, I suppose. Perhaps I need to
              raise my certainty filters.
              (And I'll bet you've typed on an old Royal or two in your time...)
              >
              Who are you calling a monkey?

              look-out-for-my-infinite-number-of-friends-ly y'rs - steve
              --
              Steve Holden +44 150 684 7255 +1 800 494 3119
              Holden Web LLC/Ltd http://www.holdenweb.com
              Skype: holdenweb http://del.icio.us/steve.holden
              Recent Ramblings http://holdenweb.blogspot.com

              Comment

              • azrael

                #22
                Re: Problem with algorithm

                Are you maybe trying to create a rainbow table, or a very big
                dictionary

                Comment

                • Robert Kern

                  #23
                  Re: Problem with algorithm

                  Paul McGuire wrote:
                  If I see farther, it is because I stand on the shoulders of an
                  infinite number of monkeys.
                  If I ever get around to writing a book on numerical methods/computational
                  science/whatever, this will be the chapter quote for my chapter on Monte Carlo
                  algorithms.

                  --
                  Robert Kern

                  "I have come to believe that the whole world is an enigma, a harmless enigma
                  that is made terrible by our own mad attempt to interpret it as though it had
                  an underlying truth."
                  -- Umberto Eco

                  Comment

                  Working...