Created
June 30, 2017 03:09
-
-
Save akshaykarnawat/fd18dcbec87e0ff0815f1afd48b606ea to your computer and use it in GitHub Desktop.
Finds the probability of two people sharing the same birthday with the given number of people in the room
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pylab | |
import numpy as np | |
# The function finds the probability of two people have the same | |
# birthday with the given number of people in the room | |
def findProbability(n): | |
x = [] # the x range of values to plot | |
y = [] # the y range of values to plot | |
p = 1 # the probability | |
# find the probability given n numbers of people in the room | |
for i in range(n): | |
# multiply by itself to get the factorial effect | |
p *= float((float((365-i))/365)) | |
x.append(i) # add x values to the list | |
y.append(1-p) # add y values to the list | |
# plot the line graph values | |
pylab.plot(x,y,linestyle='-',marker='o') | |
pylab.show() | |
# run the program | |
#findProbability(15) | |
#findProbability(23) | |
#findProbability(32) | |
#findProbability(41) | |
findProbability(350) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment