Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Birthday Chancesby atcroft (Abbot) |
on Feb 15, 2002 at 11:37 UTC ( [id://145664]=note: print w/replies, xml ) | Need Help?? |
I saw this same problem a while back myself. If I recall correctly, the answer was 50 before the odds would be better than 50-50 of 2 people in the room having the same birthday. The 1st person as 1/365th of a chance of being on a particular day, the odds the 2nd person having one other than the first is 364/365ths, the 3rd having a different birthday 363/365ths, and so forth.
As to modeling this situation, you would have to keep track of the day (potentially an array 0..364), and add people until you hit the same day for two of them. Then, you would need to simulate it multiple times (such as your $TRIALS=1024) to get an estimate. Enjoy. (The code below might give you a starting place, but may require you to run considerably longer to get a better estimate.) Update: thraxil is correct-I bow both to his math skill and to his remembering the correct answer. An article at http://www.people.virginia.edu/~rjh9u/birthday.html discusses it more. It had made me wonder when the simulations I ran with the script above seemed to fall within the range between 20 and 25....
In Section
Cool Uses for Perl
|
|