Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Infinite Monke Simulator

Introduction:

The Infinite Monkey Theorem is as follows:

"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 any given text" - taken from wikipedia (https://en.wikipedia.org/wiki/Infinite_monkey_theorem)

This console app is a simple implementation of the infinite typing monkey, which will take an input string and attempt to type out that string, and provide some analysis of runtime and number of attempts taken at the end.

Demo screenshot:

infinite monkey

(Test case: Input string "monkey", 5 trials - it must replicate the input string 5 times)

We must imagine the monkey happy.

Features:

Input Analysis:

By default, the pool of characters to choose from is only 26 lowercase characters.

The monkey will analyze the input string to check if there are uppercase characters and whitespace, then add the set of uppercase letters and whitespace to the character pool as needed.

Attempts count and runtime analyses:

The monkey will keep track of the number of attempts taken each time it tries to successfully replicate the input string.

The monkey will keep track of how much time it took and report the total and average time taken for all attempts, along with number of attempts it could do per second (to account for different computers' performance).

The Math:

Assuming a lowercase word, the chance of typing out a word of n length should be 1/((1/26) ^ n).

Example: a word of length 5 should take about 1 / ((1/26)^5) = 11881376 attempts on average. The program confirms this prediction for this simple case.

Optimization:

Instead of guessing the entire string every attempt, the monkey types one letter at a time and only continue guessing the next letter if it guesses one letter correctly.

Doing this seems to have decreased time taken by 66-75%. Nice to have but still the same time complexity.

Conclusione

The monkey is practically performing a bruteforce attack to guess the input string. At this stage, it is nothing more than a funny thought experiment and a waste of computing resource.

Quickstart Guide

Double-click the file named "InfiniteMonkeSimulator.py", patiently observe.

About

InfiniteMonkeSimulator

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages