Warning: Table './wcdrupal/cache_page' is marked as crashed and last (automatic?) repair failed query: SELECT data, created, headers, expire FROM cache_page WHERE cid = 'http://wiredcola.com/content/given-these-parameters-theres-just-over-10-chance' in /home/rcousine/wiredcola.com/includes/database.mysql.inc on line 172

Warning: Cannot modify header information - headers already sent by (output started at /home/rcousine/wiredcola.com/includes/database.mysql.inc:172) in /home/rcousine/wiredcola.com/includes/bootstrap.inc on line 531

Warning: Cannot modify header information - headers already sent by (output started at /home/rcousine/wiredcola.com/includes/database.mysql.inc:172) in /home/rcousine/wiredcola.com/includes/bootstrap.inc on line 532

Warning: Cannot modify header information - headers already sent by (output started at /home/rcousine/wiredcola.com/includes/database.mysql.inc:172) in /home/rcousine/wiredcola.com/includes/bootstrap.inc on line 533

Warning: Cannot modify header information - headers already sent by (output started at /home/rcousine/wiredcola.com/includes/database.mysql.inc:172) in /home/rcousine/wiredcola.com/includes/bootstrap.inc on line 534

Warning: Table './wcdrupal/watchdog' is marked as crashed and last (automatic?) repair failed query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Cannot modify header information - headers already sent by (output started at /home/rcousine/wiredcola.com/includes/database.mysql.inc:172)</em> in <em>/home/rcousine/wiredcola.com/includes/common.inc</em> on line <em>141</em>.', 2, '', 'http://wiredcola.com/content/given-these-parameters-theres-just-over-10-chance', '', '54.166.123.247', 1490695867) in /home/rcousine/wiredcola.com/includes/database.mysql.inc on line 172

Warning: Table './wcdrupal/watchdog' is marked as crashed and last (automatic?) repair failed query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead</em> in <em>/home/rcousine/wiredcola.com/includes/unicode.inc</em> on line <em>311</em>.', 2, '', 'http://wiredcola.com/content/given-these-parameters-theres-just-over-10-chance', '', '54.166.123.247', 1490695867) in /home/rcousine/wiredcola.com/includes/database.mysql.inc on line 172
Given these parameters, there's just over a 10% chance... | Wired Cola

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

  • warning: Cannot modify header information - headers already sent by (output started at /home/rcousine/wiredcola.com/includes/database.mysql.inc:172) in /home/rcousine/wiredcola.com/includes/common.inc on line 141.
  • : preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/rcousine/wiredcola.com/includes/unicode.inc on line 311.

...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:
# for $aref ( @fullrun) { print "\t [ @$aref ], \n"; }
for ($j=1; $j <= runs ; $j++ ) {
for ($k=0; $k <= 365 ; $k++) {
#print "$j, $k, $fullrun[$j][$k]";
if ($fullrun[$j][$k] >= bdaymatches) {
# print "incrementing...";
$foundmatches++;
}
}
}
#we really want matches/year
$foundmatches = $foundmatches / runs;
print "approx p for this formula: $foundmatches\n";
print "end of run";
# returns an array of counts of the number of people sharing each
# day of the year as a birthday.

sub yeartally()
#this is a sub because I thought that would save me zeroing things. Nope.
{
my @oneyear = ();
for ($j = 1; $j <= friends; $j++)
{
$x = int(365*rand);
$oneyear[$x]++;
# printf "%d \n", $x;
}
# print "@oneyear\n";
return @oneyear;
}

Comments

why you are writing a simulation...

when you can calculate the probability directly?
http://en.wikipedia.org/wiki/Birthday_problem

Because it's tricky...

...it's not the normal case of the Birthday Problem.

In all the well-known "generalizations" of the Birthday Problem, you'll see they only want the odds of a single collision. The question of checking for an n-way collision is much much fussier.

I mean, I assume a reasonably probability-minded person could calculate the answer, but I challenge you to try. My preliminary sketch of an answer revealed a messy hairball: it is not trivially generalizable from a 2-way collision.

Given Andrew's 212 friends, his birthday p~=1. It's something like 10e-17 that he wouldn't match at least one pair. But given that a 5-way match is what we want, you then have to calculate the probable number of 2-way matches, then the odds that any of those 2-way matches are a 3-way match, and so forth. It's a very different problem from any version of the Birthday Problem, and I didn't remember enough combinatorial mathematics to figure out the odds.

I did remember enough Perl to write a program, though!

I love programming

It's one of those things I'll never get tired of. Just knowing that I can understand the basic logic of the code makes me excited. I can't believe I actually read the full code of this post, heheh.

Hope you're well, Ryan. Give my best to TLO too.


Warning: Table './wcdrupal/watchdog' is marked as crashed and last (automatic?) repair failed query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./wcdrupal/cache_page&amp;#039; is marked as crashed and last (automatic?) repair failed\nquery: LOCK TABLES cache_page WRITE</em> in <em>/home/rcousine/wiredcola.com/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://wiredcola.com/content/given-these-parameters-theres-just-over-10-chance', '', '54.166.123.247', 1490695867) in /home/rcousine/wiredcola.com/includes/database.mysql.inc on line 172

Warning: Table './wcdrupal/watchdog' is marked as crashed and last (automatic?) repair failed query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em></em> in <em>/home/rcousine/wiredcola.com/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://wiredcola.com/content/given-these-parameters-theres-just-over-10-chance', '', '54.166.123.247', 1490695867) in /home/rcousine/wiredcola.com/includes/database.mysql.inc on line 172