# Generates all 65,536 forward probs
# for 3 sets; printing every 3000-th
# Runs on OLPC (One Laptop per child)
# with very minor changes (Python 2
# print has NO parens around args)

# Using Flu minSet joint probabilities
M = (.05, .20, .20, .10, .15, .05, .20, .05)

def iToSet(i) :
#   return the set having index i
    T = set()
    m = 1
    while i > 0 :
        r = int (i % 2)
        i = int (i / 2)
        if r == 1 : T.add(m)
        m = m + m
    return (T)

def probSet (S) :
#   return probability of set S
    p = 0.0
    k = 1
    for i in range (0,8) :
        if k in   S : p = p + M[i]
        k = k + k
    return p

# main
     
for i in range(1,256) :

    A = iToSet(i)
        
    for j in range (1,256) :
        
        B = iToSet(j)

        pA = probSet(A) 
        pB = probSet(B) 

        AB = A & B
        pAB = probSet(AB) 

        # Zero Divide, can use exception 
        if pA > 0.0:
            cpro = pAB / pA # Forward only
        else:
            cpro = 999.9    # Divide by 0
                      
        num = 256*i + j
        if num % 3000 == 0 : # print a few
           print (num, i, j, '  ', A, B, cpro)