Write a function called monkey_experiment that takes in a goal string (e.g., "methinks it is like a weasel") and a number of iterations as an argument. Run the experiment for that many iterations, and return a tuple with the highest-scoring text that was generated along with the score that it got.
Write a function called monkey_experiment that takes in a goal string (e.g., "methinks it is like a weasel") and a number of iterations as an argument. Run the experiment for that many iterations, and return a tuple with the highest-scoring text that was generated along with the score that it got.
Test results:
>>> monkey_experiment("methinks it is like a weasel",100000)
('m ojindoebjrerloiuc m oaanvl', 8)
>>> monkey_experiment("methinks it is like a weasel",100)
('yeanpqj twosisjcvqrrfu eagbi', 5)
>>> monkey_experiment("brevity is the soul of wit",100000)
('nnebptorcrytbe wogl uygdsn', 8)
>>> monkey_experiment("to be",100000)
('tofbe', 4)
>>> monkey_experiment("to be",200000)
('tbhbe', 3)
>>> monkey_experiment("to be",500000)
('eo be', 4)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 5 images