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 people, named and we will be representing the months by numbers like, January, February , March ,,December .

Then, One possible combination of birthday can be,

In this case, January () has birthdays, February() has 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 birthday (in total in this group there are birthday) and another four months (suppose June, July, September and December) each holds birthday (in total this group has 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) = .

Now, for our particular case, we must group months from months where each contains birthdays. This can be done in ways. After this again we have to choose months from remaining , where each contains birthdays. This can be done in ways.

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

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

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

Now, we still have months where each of those contains 2 birthdays. This gives a total of ways.

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

So, The probability =

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

###### Solution-2

In this method we consider a dice with 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 times for different number and same number times for other different number, i.e., what is the probability to get a state like ?

This can be solved in simple steps.

1. Among faces, of them can be taken in ways.
2. Among those faces, are groups of 's and are groups of 's. The number of ways = .
3. If we roll it times or take dices, then there are sets of and sets of . In this case, the possibilities .
4. The sample space's element number

Hence, probability

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 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 .

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 people, named and we will be representing the months by numbers like, January, February , March ,,December .

Then, One possible combination of birthday can be,

In this case, January () has birthdays, February() has 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 birthday (in total in this group there are birthday) and another four months (suppose June, July, September and December) each holds birthday (in total this group has 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) = .

Now, for our particular case, we must group months from months where each contains birthdays. This can be done in ways. After this again we have to choose months from remaining , where each contains birthdays. This can be done in ways.

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

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

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

Now, we still have months where each of those contains 2 birthdays. This gives a total of ways.

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

So, The probability =

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

###### Solution-2

In this method we consider a dice with 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 times for different number and same number times for other different number, i.e., what is the probability to get a state like ?

This can be solved in simple steps.

1. Among faces, of them can be taken in ways.
2. Among those faces, are groups of 's and are groups of 's. The number of ways = .
3. If we roll it times or take dices, then there are sets of and sets of . In this case, the possibilities .
4. The sample space's element number

Hence, probability

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 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 .

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.

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