from numpy import intersect1d, union1d
M=8# #number of male professors teaching calculus
F=5# #number of female professors teaching calculus
T=M+F #
print 'number of ways a student can choose a calculus professor\n',T
E=[2,3,5,7]# #event of choosing a prime number less than 10
F=[2,4,6,8]# #event of choosing an even number less than 10
G=intersect1d(E,F)# #event of getting an even and prime number
H=len(E)+len(F)-len(G)#
print 'event of getting an even or a prime number\n',H
E=[11,13,17,19]# #event of choosing a prime number between 10 and 20
F=[12,14,16,18]# #event of choosing an even number between 10 and 20
G=union1d(E,F)# #event of choosing a number which is prime or even
k=len(G)#
print 'number of ways of choosing a number which is prime or even\n',k
print 'a license plate contains two letters followed by three digits where first digit can not be zero'
n=26# #number of english letters
n*n# #number of ways of choosing two letters in the license plate
p=10# #number of digits (0-9)
(p-1)*p*p# #number of ways to select the three digits with the first digit not being zero
k=n*n*(p-1)*p*p#
print 'total number of license plates that can be printed\n',k
print '\n\na president ,a secretary and a treasurer has to be elected in an orga-nisation of 26 members.No person is elected to more than one postion'
t=26# #total number of members in the organisation
j=t*(t-1)*(t-2)#
print 'number of ways to elect the three officers (president,secretary,treasurer\n',j
from scipy.misc import factorial
print 'factorial of 6 : '
facto2=2*1#
facto3=3*facto2
facto4=3*facto3
facto4=4*facto3
facto5=5*facto4
facto6=6*facto5
print facto6
k=8*7*factorial(6)/factorial(6)#
print 'value of 8!/6! is:',k
j=12*11*10*factorial(9)/factorial(9)#
print 'value of 12!/9! is:',j
from scipy.misc import factorial
def func1(n,r): #calculating binomial coefficient
k=factorial(n)/(factorial(r)*factorial(n-r))#
return k
print "8C2 = ",func1(8,2)
print "9C4 = ",func1(9,4)
print "12C5 = ",func1(12,5)
print "10C3 = ",func1(10,3)
print "13C1 = ",func1(13,1)
p = factorial(10)/(factorial(10-7)*factorial(7)) #calculating 10C7
q= factorial(10)/(factorial(10-3)*factorial(3)) #calculating 10C3
print 'value of 10C7 is',p
#10-7=3 so 10C7 can also be computed as 10C3
#both p and q have same values but second method saves time and space
print 'finding the number of three-letter words using only the given six letters(A,B,C,D,E,F) without repetition'
n=6# #total number of letters
l1=n# #number of ways in which first letter of the word can be chosen
l2=n-1# #number of ways in which second letter of the word can be chosen
l3= n-2# #number of ways in which third letter can be chosen
k=l1*l2*l3#
print 'number of three-letter words possible',k
from scipy.misc import factorial
def funct1(n,p,q):
k= factorial(n)/(factorial(p)*factorial(q))#
return k
k=funct1(7,3,2) #in "BENZENE" three letters are alike(the three Es) and two are alike (the two Ns)
print 'The number of seven-letter words that can be formed using letters of the word BENZENE = ',k
print '\na set of 4 indistinguishable red coloured flags, 3 indistinguishable white flags and a blue flag is given'
j=funct1(8,4,3)
print '\nnumber of different signals ,each consisting of eight flags = ',j
from scipy.misc import factorial
print 'four objects are given (a,b,c,d) and three are taken at a time'
combinations = factorial(4)/(factorial(4-3)*factorial(3))#
print 'number of combinations of the four objects given = ',combinations
k=factorial(3)# #number of permutations of objects in a combination
permutations = combinations*k#
print 'total number of permuatations for the problem = ',permutations
from scipy.misc import factorial
def myfunc(n,r):
k=factorial(n)/(factorial(n-r)*factorial(r))#
return k
k=myfunc(8,3)
print'the number of committees of three that can be formed out of eight people = ', k
cows=myfunc(6,3) #number of ways that a farmer can choose 3 cows out of 6 cows
pigs=myfunc(5,2) #number of ways that a farmer can choose 2 pigs out of 5 pigs
hens=myfunc(8,4) #number of ways that a farmer can choose 4 hens out of 8 hens
p=cows*pigs*hens#
print 'total number of ways that a farmer can choose all these animals = ',p
from scipy.misc import factorial
#each solution to the equation can be viewed as a combination of objects
r=18# #number of objects
M=3# #kinds of object
m=factorial(r+(M-1))/(factorial(r+(M-1)-(M-1))*factorial(M-1))#
print 'number of non negative integer solutions of the given equation x+y+z=18 = ',m
from scipy.misc import factorial
c1=3# #number of toys that the youngest child should get
c2=2# #number of toys that the third child should get
c3=2# #number of toys that the second child should get
c4=2# #number of toys that the eldest son should get
m=factorial(9)/(factorial(3)*factorial(2)*factorial(2)*factorial(2))#
print 'number of ways nine toys can be divided between four children with the youngest son getting 3 toys and others getting 2 each',m
from scipy.misc import factorial
p=12# #total number of students
t=3# #number of teams or partition
print 'each partition of the students can be arranged in 3! ways as an ordered partition'
r=factorial(12)/(factorial(4)*factorial(4)*factorial(4)) #number of ordered partitions
m=r/factorial(t)# #number of unordered partitions
print 'number of ways that 12 students can be partitioned into three teams so that each team consists of 4 students',m
from numpy import floor
U=1000# #number of elements in the set of positive integers not exceeding 1000
A=U/3# #number of elements in the subset of integers divisible by 3
B=U/5# #number of elements in the subset of integers divisible by 5
C=U/7# #number of elements in the subset of integers divisible by 7
AandB=floor(U/(3*5)) #number of elements in the subset containing numbers divisible by both 3 and 5
AandC=floor(U/(3*7)) #number of elements in the subset containing numbers divisible by both 3 and 7
BandC=floor(U/(5*7)) #number of elements in the subset containing numbers divisible by both 5 and 7
AandBandC=floor(U/(3*5*7)) #number of elements in the subset containing numbers divisible by 3,5 and 7
s=U-(A+B+C)+(AandB+AandC+BandC)-(AandBandC)# # By inclusion-exclusion principle
S=round(s)#
print 'The number of integers in the set U, which are not divisible by 3,5 and 7 is',S