How Cheenta works to ensure student success?
Explore the Back-Story

A Probability Birthday problem along with Julia Programming

Probability theory is nothing but common sense reduced to calculation.

Pierre-Simon Laplace

Today we will be discussing a problem from the second chapter of A First Course in Probability(Eighth Edition) by Sheldon Ross.

Let's see what the problem says:

Describing the Problem

The problem(prob-48) says:

Given 20 people, what is the probability that among the 12 months in the year, there are 4 months containing exactly 2 birthdays and 4 containing exactly 3 birthdays?

So, what do we mean by this? Let's suppose we have 20 people, named p_1,p_2,\cdots , p_{20} and we will be representing the months by numbers like, January\to 1, February \to 2 , March \to 3 ,\cdots,December \to 12.

Then, One possible combination of birthday can be,

People Name Birthday Month
p_101
p_205
p_309
p_404
p_507
p_612
p_703
p_809
p_906
p_{10}11
p_{11}12
p_{12}01
p_{13} 07
p_{14} 02
p_{15} 09
p_{16} 12
p_{17} 02
p_{18} 11
p_{19} 06
p_{20} 08

In this case, January (01) has 2 birthdays, February(02) has 2 birthdays. Similarly we can find the number of birthday in each month. But in our question it is said that one possible arrangement exist where any four months (suppose January, February, March and April) each holds 2 birthday (in total in this group there are 4\times 2 = 8 birthday) and another four months (suppose June, July, September and December) each holds 3 birthday (in total this group has 4\times 3 = 12 birthdays). We have to find the probability of existence of such groups.

I hope the problem is clear. Let's see how to solve this.

Solution - 1

To solve this problem one must notice the most important point. This problem treats each people in same footing, means they are indistinguishable. Normally, we humans are distinguishable as you can see people's face or maybe use their name to make difference.

So, The number of all possible combinations (outcome) = 12^{20}.

Now, for our particular case, we must group 4 months from 12 months where each contains 2 birthdays. This can be done in {12 \choose 4} ways. After this again we have to choose 4 months from remaining 8, where each contains 3 birthdays. This can be done in {8 \choose 4} ways.

So, we can choose months (or the month combination is ) in {12 \choose 4}{8 \choose 4} ways. Using multinomial theorem, we can write this number equals to {12 \choose 4 4 4} (we will not use this).

Now, we have 20 people and we have to to assign months with them.

Remember we have to take 3 people and give them one single month. This can be done in {20 \choose 3} ways. Again we have to take 3 people and group them. This time the possible ways are {17 \choose 3}. Again doing the same gives us {14 \choose 3} ways (this is done 4 times as we have 4 such months which contains 3 birthdays). So, for this group the number of possible combinations is {20 \choose 3} {17 \choose 3}  {14 \choose 3}  {11 \choose 3}.

Now, we still have 4 months where each of those contains 2 birthdays. This gives a total of {8 \choose 2}  {6 \choose 2}  {4 \choose 2}  {2 \choose 2} ways.

So, the total numbers of ways of assigning 20 people to those months is

    \[{20 \choose 3} {17 \choose 3}  {14 \choose 3 } {11 \choose 3}  {8 \choose 2}  {6 \choose 2}  {4 \choose 2}  {2 \choose 2} = \frac{20!}{3!\cdot 17!}  \frac{17!}{3!\cdot 14!} \frac{14!}{3!\cdot 11!}   \frac{11!}{3!\cdot 8!}   \frac{8!}{2!\cdot 6!} \frac{6!}{2!\cdot 4!}  \frac{4!}{2!\cdot 2!}  \frac{2!}{2!\cdot 0!}  = \frac{20!}{12^4}\]

So, The probability = {{12\choose 4}{8\choose 4}\frac{20!}{12^4}\over 12^{20}} = 0.00106042009902

Easy right? This can also be solved using a analogy of dice with 12 sides.

Solution-2

In this method we consider a dice with 12 sides. Each person's birthday is within 12 months and each of them are independent. So, If that dice is rolled 20 times, then what is the probability to get same number 3 times for 4 different number and same number 2 times for other 4 different number, i.e., what is the probability to get a state like 11223344666777888999?

This can be solved in 4 simple steps.

  1. Among 12 faces, 8 of them can be taken in a={12 \choose 8} = 495 ways.
  2. Among those 8 faces, 4 are groups of 2's and 4 are groups of 3's. The number of ways = b = {8 \choose 4}{4 \choose 4} = 70.
  3. If we roll it 20 times or take 20 dices, then there are 4 sets of 3 and 4 sets of 2. In this case, the possibilities c = \frac{20!}{(3!)^4 (2!)^4}.
  4. The sample space's element number d = 12^{20}

Hence, probability =\frac{a\times b \times c}{d} = 0.0010604200990

Whenever I solve this type of problems, It always feel like may be !! maybe!! I have made some mistake. To be sure that we are correct, we should perform experiment with a dice or may be take many groups of 20 people and calculate probability. But It is practically impossible!!

Not quite... We can always use programming language to do the experiments and verify.

Verifying using Julia

First we have to know few tricks.

arr = [2,6,2,10]
#Creates an array

Now, how can we know if there are two 2's inside of this array?, an easy solution will be

arr.==2
#Check if any element equal to 2
#This gives an output as:
#BitVector: [true,false,true,false]

And then we use sum

sum(arr.==2)
#return number of times 2 is there
#output: 2

Using this we write a simple code:

begin
    function prob(n::Int)
	favour = 0
	for ex_num=1:n
		months = rand(1:12,20)
		nums = [sum(months.==i) for i=1:12]
		if sum(nums.==3)==4 && sum(nums.==2)==4
			favour += 1
		end
	end
	probability = favour/n
    end
end

This function beautifully give you the value. We need more sample, so I have used n=1,00,00,000.

This gives the result:3

prob_10_000_000 = prob(10_000_000)
#output: 0.0010616

Beautiful isn't it?, just using few lines of code we have verified our answer.

I encourage you to play with the code.

This is all for today. I hope you have learnt something new.

Probability theory is nothing but common sense reduced to calculation.

Pierre-Simon Laplace

Today we will be discussing a problem from the second chapter of A First Course in Probability(Eighth Edition) by Sheldon Ross.

Let's see what the problem says:

Describing the Problem

The problem(prob-48) says:

Given 20 people, what is the probability that among the 12 months in the year, there are 4 months containing exactly 2 birthdays and 4 containing exactly 3 birthdays?

So, what do we mean by this? Let's suppose we have 20 people, named p_1,p_2,\cdots , p_{20} and we will be representing the months by numbers like, January\to 1, February \to 2 , March \to 3 ,\cdots,December \to 12.

Then, One possible combination of birthday can be,

People Name Birthday Month
p_101
p_205
p_309
p_404
p_507
p_612
p_703
p_809
p_906
p_{10}11
p_{11}12
p_{12}01
p_{13} 07
p_{14} 02
p_{15} 09
p_{16} 12
p_{17} 02
p_{18} 11
p_{19} 06
p_{20} 08

In this case, January (01) has 2 birthdays, February(02) has 2 birthdays. Similarly we can find the number of birthday in each month. But in our question it is said that one possible arrangement exist where any four months (suppose January, February, March and April) each holds 2 birthday (in total in this group there are 4\times 2 = 8 birthday) and another four months (suppose June, July, September and December) each holds 3 birthday (in total this group has 4\times 3 = 12 birthdays). We have to find the probability of existence of such groups.

I hope the problem is clear. Let's see how to solve this.

Solution - 1

To solve this problem one must notice the most important point. This problem treats each people in same footing, means they are indistinguishable. Normally, we humans are distinguishable as you can see people's face or maybe use their name to make difference.

So, The number of all possible combinations (outcome) = 12^{20}.

Now, for our particular case, we must group 4 months from 12 months where each contains 2 birthdays. This can be done in {12 \choose 4} ways. After this again we have to choose 4 months from remaining 8, where each contains 3 birthdays. This can be done in {8 \choose 4} ways.

So, we can choose months (or the month combination is ) in {12 \choose 4}{8 \choose 4} ways. Using multinomial theorem, we can write this number equals to {12 \choose 4 4 4} (we will not use this).

Now, we have 20 people and we have to to assign months with them.

Remember we have to take 3 people and give them one single month. This can be done in {20 \choose 3} ways. Again we have to take 3 people and group them. This time the possible ways are {17 \choose 3}. Again doing the same gives us {14 \choose 3} ways (this is done 4 times as we have 4 such months which contains 3 birthdays). So, for this group the number of possible combinations is {20 \choose 3} {17 \choose 3}  {14 \choose 3}  {11 \choose 3}.

Now, we still have 4 months where each of those contains 2 birthdays. This gives a total of {8 \choose 2}  {6 \choose 2}  {4 \choose 2}  {2 \choose 2} ways.

So, the total numbers of ways of assigning 20 people to those months is

    \[{20 \choose 3} {17 \choose 3}  {14 \choose 3 } {11 \choose 3}  {8 \choose 2}  {6 \choose 2}  {4 \choose 2}  {2 \choose 2} = \frac{20!}{3!\cdot 17!}  \frac{17!}{3!\cdot 14!} \frac{14!}{3!\cdot 11!}   \frac{11!}{3!\cdot 8!}   \frac{8!}{2!\cdot 6!} \frac{6!}{2!\cdot 4!}  \frac{4!}{2!\cdot 2!}  \frac{2!}{2!\cdot 0!}  = \frac{20!}{12^4}\]

So, The probability = {{12\choose 4}{8\choose 4}\frac{20!}{12^4}\over 12^{20}} = 0.00106042009902

Easy right? This can also be solved using a analogy of dice with 12 sides.

Solution-2

In this method we consider a dice with 12 sides. Each person's birthday is within 12 months and each of them are independent. So, If that dice is rolled 20 times, then what is the probability to get same number 3 times for 4 different number and same number 2 times for other 4 different number, i.e., what is the probability to get a state like 11223344666777888999?

This can be solved in 4 simple steps.

  1. Among 12 faces, 8 of them can be taken in a={12 \choose 8} = 495 ways.
  2. Among those 8 faces, 4 are groups of 2's and 4 are groups of 3's. The number of ways = b = {8 \choose 4}{4 \choose 4} = 70.
  3. If we roll it 20 times or take 20 dices, then there are 4 sets of 3 and 4 sets of 2. In this case, the possibilities c = \frac{20!}{(3!)^4 (2!)^4}.
  4. The sample space's element number d = 12^{20}

Hence, probability =\frac{a\times b \times c}{d} = 0.0010604200990

Whenever I solve this type of problems, It always feel like may be !! maybe!! I have made some mistake. To be sure that we are correct, we should perform experiment with a dice or may be take many groups of 20 people and calculate probability. But It is practically impossible!!

Not quite... We can always use programming language to do the experiments and verify.

Verifying using Julia

First we have to know few tricks.

arr = [2,6,2,10]
#Creates an array

Now, how can we know if there are two 2's inside of this array?, an easy solution will be

arr.==2
#Check if any element equal to 2
#This gives an output as:
#BitVector: [true,false,true,false]

And then we use sum

sum(arr.==2)
#return number of times 2 is there
#output: 2

Using this we write a simple code:

begin
    function prob(n::Int)
	favour = 0
	for ex_num=1:n
		months = rand(1:12,20)
		nums = [sum(months.==i) for i=1:12]
		if sum(nums.==3)==4 && sum(nums.==2)==4
			favour += 1
		end
	end
	probability = favour/n
    end
end

This function beautifully give you the value. We need more sample, so I have used n=1,00,00,000.

This gives the result:3

prob_10_000_000 = prob(10_000_000)
#output: 0.0010616

Beautiful isn't it?, just using few lines of code we have verified our answer.

I encourage you to play with the code.

This is all for today. I hope you have learnt something new.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Knowledge Partner

Cheenta is a knowledge partner of Aditya Birla Education Academy
Cheenta

Cheenta Academy

Aditya Birla Education Academy

Aditya Birla Education Academy

Cheenta. Passion for Mathematics

Advanced Mathematical Science. Taught by olympians, researchers and true masters of the subject.
JOIN TRIAL
support@cheenta.com
Menu
Trial
Whatsapp
magic-wandrockethighlight