Created
February 24, 2017 11:18
-
-
Save zapthedingbat/d5ad04329110fcdc1f5e46722078c531 to your computer and use it in GitHub Desktop.
Calculating the probability that a member of a team shares their birthday with someone else in the same team.
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
//https://en.wikipedia.org/wiki/Birthday_problem#Calculating_the_probability | |
function p(n){ | |
let a = 1; | |
for(let i = 0; i < n; i++){ | |
a *= ((365 - i) / 365); | |
} | |
return 1 - a; | |
} | |
const chance = p(parseInt(process.argv.pop())) * 100; | |
console.log(`There is a ${chance}% chance of two people in the same team sharing the same birthday`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment