Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions