Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sameBirthdayInCrowd(n):
- if n != int(n) or n <= 0 or n > 365:
- return None
- product = 1
- for i in range(n):
- product *= (365 - i)/365
- return 1 - product
- def sameBirthdayWithMe(n):
- if n != int(n) or n <= 0:
- return None
- return 1 - (364/365)**n
- # MAIN FUNCTION
- numbers = list(range(1, 366))
- import matplotlib.pyplot as plt
- plt.plot([sameBirthdayInCrowd(n) for n in numbers], label="Same Birthday in crowd of n people")
- plt.plot([sameBirthdayWithMe(n) for n in numbers], label="Same Birthday with me in crowd of n people")
- plt.xlabel("n")
- plt.ylabel("f(n)")
- plt.legend()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement