Guest User

Untitled

a guest
Nov 23rd, 2018
141
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3.  
  4. alphabet = list('ABCNOTU')
  5.  
  6. import itertools
  7. import random
  8.  
  9.  
  10. def typing_monkey(alphabet):
  11.     while True:
  12.         yield random.choice(alphabet)
  13.  
  14.  
  15. def type_until_word(goal, alphabet):
  16.     random_letter = typing_monkey(alphabet)
  17.     goal = list(goal)
  18.     n = len(goal)
  19.     random_word = [next(random_letter) for _ in range(n)]
  20.     for i in itertools.count():
  21.         if random_word == goal:
  22.             #print('Found %r after %d iterations!' % (''.join(goal), i))
  23.             print('.', end='', flush=True)
  24.             return i
  25.         random_word = random_word[1-n:] + [next(random_letter)]
  26.  
  27. N = 300
  28. monkey_1 = [type_until_word('COCONUT', alphabet) for _ in range(N)]
  29. print('Average for Monkey 1 : %.0f letters' % (sum(monkey_1) / N))
  30. monkey_2 = [type_until_word('TUNOCOC', alphabet) for _ in range(N)]
  31. print('Average for Monkey 2 : %.0f letters' % (sum(monkey_2) / N))
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×