Archive - Mar 29, 2010

Date
  • All
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

Given these parameters, there's just over a 10% chance...

...that 5 of Andrew's 212 friends share a birthday.

#!/usr/bin/perl

#monte carlo calculation on Andrew's Birthday question.
# In short, this code allows a general test of the question:
# "if I have x friends, what are the chances that any y of
# them share a birthday?" It does so using Monte Carlo technique.
# runs should be set high (at least 1000, maybe higher) to give a
# good answer. I don't know what gives good confidence here.

# init a few things. bdaymatches is how many friends share one birthday.
use constant friends => 212;
use constant runs => 10000;
use constant bdaymatches => 5;
$foundmatches = 0;

# this loop calls yeartally once per run, adding each run to the array of
# runs called fullrun.
for ($i = 1; $i <= runs; $i++)
{
@temp = &yeartally;
$fullrun[$i] = [ @temp ];
#print "@temp\n";
# printf "THIS IS A YEAR BREAK \n";
}
#debug printing of the array: