Question: The infinite monkey theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely

The infinite monkey theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type the complete works of William Shakespeare.

In this program you will put this theorem to the test by using the rand() function to create random sequences of letters and the underscore symbol until the desired sequence is created. While attempting to create the desired sequence you must count the number of random attempts needed to create the sequence and measure the time to create the sequence.

Our ultimate goal is to create the phrase: to_be

Please note that it will take a few minutes on average to randomly generate this phrase.

The attempted sequence is: t

It took 13 attempts to create the sequence: t

Elapsed time is 0.001358 seconds.

The attempted sequence is: to

It took 235 attempts to create the sequence: to

Elapsed time is 0.009133 seconds.

The attempted sequence is: to_

It took 26653 attempts to create the sequence: to_

Elapsed time is 0.555479 seconds.

The attempted sequence is: to_b

It took 98377 attempts to create the sequence: to_b

Elapsed time is 2.062023 seconds.

The attempted sequence is: to_be

It took 1.90588e+007 attempts to create the sequence: to_be

Elapsed time is 420.934171 seconds.

You can see that it would take the monkey quite a while to just type this short phrase from Hamlet without any errors.

To be, or not to be, that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles And by opposing end them.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!