Still the only person on here to actually use some math. Something you seem strangely incapable of.
import math
def calculate_probability(monkeys, time_seconds, target_phrase):
# Define the character set (assuming lowercase and space for simplicity)
charset = 'abcdefghijklmnopqrstuvwxyz '
charset_size = len(charset)
# Length of the target phrase
phrase_length = len(target_phrase.lower())
# Total number of characters typed by all monkeys
total_characters = monkeys * time_seconds
# Probability of typing the target phrase correctly in one attempt
phrase_probability = (1 / charset_size) ** phrase_length
# Number of possible attempts to type the phrase
possible_attempts = total_characters - phrase_length + 1
# Probability of at least one correct attempt
probability = 1 - (1 - phrase_probability) ** possible_attempts
return probability
# Inputs
monkeys = 100
time_seconds = 60 * 60 # 1 hour
target_phrase = "To be or not to be"
# Calculate and print the probability
prob = calculate_probability(monkeys, time_seconds, target_phrase)
print(f"Probability of typing '{target_phrase}' in {time_seconds} seconds with {monkeys} monkeys: {prob:.10f}")