Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coin_toss_differential.py
- from random import randint
- h = t = 0
- coin_side = {0: 0, 1: 0}
- prev = [-1, 0]
- for z in '.'*99999:
- flip = randint(0, 1)
- if flip:
- h += 1
- else:
- t += 1
- if prev[0] == flip:
- prev[1] += 1
- else:
- coin_side[flip] = max(coin_side[flip], prev[1])
- prev = [flip,1]
- d = h-t
- sh = coin_side[1]
- st = coin_side[0]
- 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