Re: Problem with algorithm
On Apr 13, 10:22 am, Michael Bentley <mich...@jedimi ndworks.com>
wrote:
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)
On Apr 13, 10:22 am, Michael Bentley <mich...@jedimi ndworks.com>
wrote:
On Apr 13, 2007, at 9:19 AM, Paul McGuire wrote:
>
>
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!")
>
If you just expand the length to five million* or so, one of those
strings will contain all the works of Shakespeare.
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!")
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