xamples
epeat
ode
pproach
ptimize
est
How many students need to be in a class such that at least two students share the same birthday?
For birthday, we mean day of the year e.g. March 4th
function birthdayProbability(numSimulations){
var numStudents = 0;
for(let i = 0; i < numSimulations; i++){
let studentsBday = [];
do{
studentsBday.push(Math.round(Math.random()*364));
var index = studentsBday.indexOf(studentsBday[studentsBday.length - 1]);
}while(index === studentsBday.length - 1)
numStudents += studentsBday.length;
}
return Math.ceil(numStudents / numSimulations);
}
birthdayProbability(10000);
//we can repeat the simulations until the solution is stable
//here we arbitrarily select a sample size of 10,000