Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. # Checks longest run lengths in n attempts of n flips
  2.  
  3. import random
  4.  
  5. attempts = 10000
  6. results = {}
  7.  
  8. while attempts != 0:
  9.     attempts -= 1
  10.     maxRun = 0
  11.     last = -1
  12.     count = 0
  13.  
  14.     flips = 200
  15.  
  16.     while flips != 0:
  17.         flips -= 1
  18.  
  19.         num = random.randint(0,1)
  20.  
  21.         if last == -1:
  22.             last = num
  23.             count += 1
  24.         elif num == last:
  25.             count += 1
  26.         else:
  27.             if count > maxRun:
  28.                 maxRun = count
  29.                 count = 1
  30.  
  31.     if maxRun in results:
  32.         results[maxRun] += 1
  33.     else:
  34.         results[maxRun] = 1
  35.  
  36. for key, value in results.items():
  37.     print(key, value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement