Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Hit the run button above this to test.

import random as rd


def lookingForSequence( seq = "" ):
        flips = ""
        while len(flips) < len(seq) or flips[-len(seq):] != seq:
                flips += "H" if rd.random() > 0.5 else "T" 
        return len(flips)
    

mean = lambda arr: sum(arr)/float(len(arr))

seq_ = ["HTH", "HTT"]

npeople = int(1E5)

for seq in seq_:
        room_ = [1]*npeople
        for person in xrange(npeople):
                room_[person] = lookingForSequence(seq)
        numflips = mean(room_)
        print "Avg. # of flips for %s is %.2f"%(seq,numflips)