Skip to content

Instantly share code, notes, and snippets.

@zapthedingbat
Created February 24, 2017 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapthedingbat/d5ad04329110fcdc1f5e46722078c531 to your computer and use it in GitHub Desktop.
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.
//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