Advertisement
here2share

# coin_toss_differential.py

Nov 28th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. # coin_toss_differential.py
  2.  
  3. from random import randint
  4.  
  5. h = t = 0
  6. coin_side = {0: 0, 1: 0}
  7. prev = [-1, 0]
  8.  
  9. for z in '.'*99999:
  10.     flip = randint(0, 1)
  11.  
  12.     if flip:
  13.         h += 1
  14.     else:
  15.         t += 1
  16.     if prev[0] == flip:
  17.         prev[1] += 1
  18.     else:
  19.         coin_side[flip] = max(coin_side[flip], prev[1])
  20.         prev = [flip,1]
  21.        
  22.     d = h-t
  23.     sh = coin_side[1]
  24.     st = coin_side[0]
  25.  
  26.     print 'heads = %d\t(longest seq = %d)\t\ttails = %d\t(longest seq = %d)\t\tdifference = %d' % (h,sh,t,st,d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement