Pseudo Infinite Monkey Theorem

Share your advanced PureBasic knowledge/code with the community.
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Pseudo Infinite Monkey Theorem

Post by Nituvious »

I know this is stupid, but it was exciting to get "Hello" in 210k passes!

Code: Select all

Global Dim Letters.s(36)

#NO_PUNCTUATION			= 0
#SIMPLE_PUNCTUATION		= 1
#COMPLETE_PUNCTUATION	= 2
#NO_NUMERICAL				= 3
#NO_NUMERICALPUNCTUATION = 4

Define.l IMT_Type = #NO_NUMERICALPUNCTUATION
Define.s stringToMake.s = "Hello World!"
Select IMT_Type ;{ What kind of monkey do you have?
	Case #NO_PUNCTUATION
		For n = 97 To 122
			Letters.s(z) = Chr(n)
			z + 1
		Next n
		Letters.s(26) = Space(1)
		Letters.s(27) = "1"
		Letters.s(28) = "2"
		Letters.s(29) = "3"
		Letters.s(30) = "4"
		Letters.s(31) = "5"
		Letters.s(32) = "6"
		Letters.s(33) = "7"
		Letters.s(34) = "8"
		Letters.s(35) = "9"
		Letters.s(36) = "0"

	Case #SIMPLE_PUNCTUATION
		ReDim Letters.s(40)
		For n = 97 To 122
			Letters.s(z) = Chr(n)
			z + 1
		Next n
		Letters.s(26) = Space(1)
		Letters.s(27) = "1"
		Letters.s(28) = "2"
		Letters.s(29) = "3"
		Letters.s(30) = "4"
		Letters.s(31) = "5"
		Letters.s(32) = "6"
		Letters.s(33) = "7"
		Letters.s(34) = "8"
		Letters.s(35) = "9"
		Letters.s(36) = "0"
		Letters.s(37) = "."
		Letters.s(38) = ","
		Letters.s(39) = "?"
		Letters.s(40) = "!"

	Case #COMPLETE_PUNCTUATION
		ReDim Letters.s(94)
		For n = 33 To 126
			Letters.s(z) = Chr(n)
			z + 1
		Next n
		Letters.s(94) = Space(1)

	Case #NO_NUMERICAL
		ReDim Letters.s(30)
		For n = 97 To 122
			Letters.s(z) = Chr(n)
			z + 1
		Next n
		Letters.s(26) = Space(1)
		Letters.s(27) = ","
		Letters.s(28) = "."
		Letters.s(29) = "?"
		Letters.s(30) = "!"

	Case #NO_NUMERICALPUNCTUATION
		ReDim Letters.s(26)
		For n = 97 To 122
			Letters.s(z) = Chr(n)
			z + 1
		Next n
		Letters.s(26) = Space(1)

EndSelect ;}


OpenConsole() : ConsoleTitle("Pseudo-Infinite Monkey Theorem")

sTimer = ElapsedMilliseconds()
While UCase(stringToMake.s) <> UCase(formedString.s)
	count.l + 1 : formedString.s = ""
	For s = 0 To Len(stringToMake.s) - 1
		formedString.s + Letters(Random(ArraySize(Letters())))
	Next s
	PrintN(Str(count) + ": " + formedString.s)
Wend
eTimer = ElapsedMilliseconds() - sTimer
PrintN(#LF$ + "Finished creating the sentence in " + Str(count.l) + " attempts. It took " + Str(eTimer/1000) + " seconds.")
Input()
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: Pseudo Infinite Monkey Theorem

Post by Rook Zimbabwe »

It took my machine quite a bit longer to get to hello... 328k
BUT
{joke}
Then it asked me... DO YOU WANT TO PLAY A GAME?
{/joke}

SKYNET LIVES!!! :wink:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: Pseudo Infinite Monkey Theorem

Post by Rook Zimbabwe »

2nd time... past 2,000,000+ still running and no punctuatiom marks yet...
Image
:mrgreen: I got me some stoopid monkeys this time!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: Pseudo Infinite Monkey Theorem

Post by Nituvious »

I had it run all night(about 13 hours total) to create "Hello world." and didn't get any results! However, a random pause I found this
33292221: u dumb.!2ubz
:o I don't think my laptop likes me very well.
▓▓▓▓▓▒▒▒▒▒░░░░░
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Pseudo Infinite Monkey Theorem

Post by c4s »

I think a random text generator could get interesting: A good start would be to randomly alternate between vowels and consonants. Then disallow the obviously not usable combinations such as more than 2 consonants/vowels after each other or pointless "jk", "xc", "wq" etc.
I once did that years ago (with German umlauts and common combinations like "sch", "st", "sp" ...) and the results weren't that random, actually quite funny... it somehow looked like Finnish. :D
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Pseudo Infinite Monkey Theorem

Post by Demivec »

Nituvious wrote:I had it run all night(about 13 hours total) to create "Hello world." and didn't get any results! However, a random pause I found this
33292221: u dumb.!2ubz
:o I don't think my laptop likes me very well.
I made some modifications to your code to speed it up considerably. I also shortened the target string and changed the count variable to a quad. It took only 8.25 hours to accomplished the target. :)
Define.l IMT_Type = #NO_NUMERICAL
Define.s stringToMake.s = "Why me?!"

Finished creating the sentence 'Why me?!' in 105342152072 attempts. It took 29730 seconds.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: Pseudo Infinite Monkey Theorem

Post by Joakim Christiansen »

c4s wrote:I think a random text generator could get interesting: A good start would be to randomly alternate between vowels and consonants. Then disallow the obviously not usable combinations such as more than 2 consonants/vowels after each other or pointless "jk", "xc", "wq" etc.
I once did that years ago (with German umlauts and common combinations like "sch", "st", "sp" ...) and the results weren't that random, actually quite funny... it somehow looked like Finnish. :D
Good idea!

And if storing the random seed one could compress stuff like "hello world" into 4 byte values (.l) when found. It would take a damn long time though to compress a text file and in some situations it might just hang forever (but would be fun to make).
I like logic, hence I dislike humans but love computers.
User avatar
pcfreak
User
User
Posts: 75
Joined: Sat May 22, 2004 1:38 am

Re: Pseudo Infinite Monkey Theorem

Post by pcfreak »

My monkey was way too silly. Even after >2 billion I only got things like this:
Image
:?
kvitaliy
Enthusiast
Enthusiast
Posts: 162
Joined: Mon May 10, 2010 4:02 pm

Re: Pseudo Infinite Monkey Theorem

Post by kvitaliy »

Problem is similar to solving a password length of 13 characters brute force. Even with the brute force the problem is solved according to the power the computer from several months to several years! And with a random selection problem in general seems impossible in the foreseeable future.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Pseudo Infinite Monkey Theorem

Post by Demivec »

pcfreak wrote:My monkey was way too silly. Even after >2 billion I only got things like this:
Was that a simulated screen image? Your monkey seemed to be counting down instead of up. :)

I had to speed up the code and shorten the length of the string to match so that I could see a solution in under year.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: Pseudo Infinite Monkey Theorem

Post by Rook Zimbabwe »

pcfreak wrote:My monkey was way too silly. Even after >2 billion I only got things like this:
Image
:?
DUDE... right on -1227054834 you got famsvmorbxzy!!! That is monkey for "where is my bananna!" :mrgreen:

I think it is negative because the number is too high... I wonder if there will be a rollover or if the computer will just crash when it gets to 0
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: Pseudo Infinite Monkey Theorem

Post by Joakim Christiansen »

Rook Zimbabwe wrote:I think it is negative because the number is too high... I wonder if there will be a rollover or if the computer will just crash when it gets to 0
It will just roll over.

OR maybe the internet will crash.
I like logic, hence I dislike humans but love computers.
Post Reply