Skip to content

Instantly share code, notes, and snippets.

@juliandescottes
Created July 27, 2013 08:07
Show Gist options
  • Save juliandescottes/6094200 to your computer and use it in GitHub Desktop.
Save juliandescottes/6094200 to your computer and use it in GitHub Desktop.
Birthday problem - in javascript \o/ cf http://en.wikipedia.org/wiki/Birthday_problem
// PARADOX ! Inception-style
var paradox = function(setSize,p){
Math.sqrt(2*setSize*Math.log(1/(1-p)))
};
// So that's the generic formula.
// Applied to the usual "over 50% of prob to have 2 people with the same birthday"
paradox(365, 0.5); // => 22.49
@jdspugh
Copy link

jdspugh commented Jul 17, 2022

var paradox = function(setSize,p){
  return Math.sqrt(2*setSize*Math.log(1/(1-p)))
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment