#! /usr/bin/env python # # Written by: # -- # John L. Weatherwax 2006-08-28 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- import sys import numpy as np def p_A(): """ Computes P(A) as specified for this problem """ # Do n==0 by hand: n = 0 t = 4./(12.-n) # Do the other n's: for n in range(1,9): ks = np.asarray( range(1,n+1) ) fr = (9. - ks)/(13. - ks) p = np.prod( fr**3 ) t += p * ( 4./(12.-n ) ) return t def p_B(): """ Computes P(B) as specified for this problem """ # Do n==0 by hand: n = 0 t = ( (8.-n)/(12.-n) ) * ( 4. / (12.-n) ) # Do the other n's: for n in range(1,8): ks = np.asarray( range(1,n+1) ) fr = (9. - ks)/(13. - ks) p = np.prod( fr**3 ) t += p * ( (8.-n)/(12.-n) ) * ( 4. / (12.-n) ) return t def p_C(): """ Computes P(C) as specified for this problem """ # Do n==0 by hand: n = 0 f1 = (8.-n)/(12.-n) f2 = 4. / (12.-n) t = f1**2 * f2 # Do the other n's: for n in range(1,8): ks = np.asarray( range(1,n+1) ) fr = (9. - ks)/(13. - ks) p = np.prod( fr**3 ) f1 = (8.-n)/(12.-n) f2 = 4. / (12.-n) t += p * ( f1**2 ) * f2 return t if __name__ == "__main__" : print p_A() print p_B() print p_C() print p_A() + p_B() + p_C()