SHARE
TWEET

Untitled

a guest Nov 23rd, 2018 106 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top