One2Swing Daily
Friday, May 28, 2004
A Neat Party Trick (to wow friends and/or make money)
So I've gotten a few comments lately.
"You're not really that big a geek are you?"
So I'd like to take this opportnity to write about one of my favorite probability problems as I'm sure some of you will appreciate this.
For the rest of you, keep reading, because this is actually a VERY cool party trick that you can use to win yourself some money for that next workshop you've been wanting to attend. (And there's the swing dancing tie-in)
Here is the original form of this bet / probability problem:
You are in a crowded room and talking to a chump, er... acquaintance. Then you bring up the subject of birthdays and then nonchalantly say to said chump:
"Hey, I'll bet you $20 that at least two people in this room have the same birthday."
Your acquaintance quickly counts that there are 23 people in the room. He then reminds himself that there are 365 days in a year. And says he'll take your bet.
So who's more likely to win?
Now if you're smart, you will say "The person who says there are at least two of the same birthday in the room" will be the winning bet. Why? Because otherwise there would be no point to this article .
Anyway, you'd be right too. (even though intuition (including MINE) would seem to make you think otherwise).
A different way of putting it is this:
There are 23 people in a room. You tell each person to pick a number from 1 to 365 and write it down. You then gather the numbers and declare you will take bets that at least two people wrote the same number.
Makes it sound like the possibility is even less when you put it that way.
But here it is. If there are 23 people in the room, you have a slightly better than 50% chance (50.7% to be more exact) that two of them have the same birthday. (If there are 25 people in the room, your chances go up to approximately 56%). With 30 people your chances go up to a whopping 70.6% (and as far as the betting goes, you'll notice that in some swing classes you'll get upwards of 30 people). ( hmmmm ...
)
Another example. Instead of the number 365, choose 300. Your chances are even better now! Say your bet is that all the people in the room "Choose a number between 1 and 300", with 23 people you odds are now 57.9% (instead of the 50.7% for birthdays (365))).
I have at the end of this article more numbers you may be interested in as far as odds and betting goes, but other than that, that's all you need to know about the betting part.
Now if you want the geeky proof, read on! (Warning! Warning! It gets really geeky!)
A = the probability of two people having the same number
As a probability and its opposite must add up to 100% (if the probability of A happening is 60% or .6, the probability of it A not happening is 40% or .4), then
A = 1 - the probability of A NOT Happening
A = 1 - NO TWO PEOPLE having the same number (let's call this B)
B = the probability of NO TWO PEOPLE having the same number
A = 1 - B
C = the target number
e.g.
C = 365 for the birthday bet (365 days in a year)
C = 300 for the "pick a number between 1 and 300" bet
etc.
D = number of people
With me?
The easiest way to show this is to plug in numbers.
Let's start in a room of 5 people not having the same birthday:
C = 365
D = 5
B =
C * (C-1) * (C-2) * ... * (C - D + 1)
-------------------------------------
C^D (C to the Dth Power)
or
B =
365 * 364 * 363 * 362 * 361
------------------------------
365 * 365 * 365 * 365 * 365
B = 6302555018760 / 6478348728125
B = .972864
A = 1 - B = .0271355
A = 2.7% chance out of 5 people, 2 will have the same birthday.
Do the same calculation and you'll find at D = 23 you pass the "breakeven" point (50.7%).
Have I ever actually made this bet?
Errhmm.. well, let's move on shall we?
Here is a perl program I wrote to test it out. Runs on pretty much any unix/linux. If you use Windows, you need to install ActivePerl (from a company called ActiveState. Just do a search on "active perl" and it should come up).
#!/usr/bin/perl
$c=$ARGV[0];
while ($c eq "") {
print "Enter a number for D (e.g. 365 for bday bet): ";
chop($c=);
}
#print "Using c = $c\n";
%numhash=();
$nomatch=1;
$numbers=0;
$picknum=0;
# while there is no two matching numbers, loop
while($nomatch) {
$numbers++;
# pick a random number
$picknum = int(rand($c)) + 1;
# if the number does not match, then mark it as picked,
# otherwise ,if it matches, output how many picks to get to
# the matched number
if ($numhash{$picknum} eq "HOLYCOW") {
$nomatch=0;
} else {
$numhash{$picknum}="HOLYCOW";
}
}
print "FOUND MATCH FOR D: $c on the draw number $numbers\n";
Some sample output for "365" (i.e. two identical birthdays)
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 14 (WINNER)
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 23 (WINNER)
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 14 (WINNER)
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 43
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 25
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 43
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 29
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 48
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 10 (WINNER)
[byau@netmanage01 byau]$ ./test.pl 365
FOUND MATCH FOR D: 365 on the draw number 21 (WINNER)
5 out of 10 times we got a match in 23 or less draws!!
Want more? Here is a sample script you can use to find your chances of winning! Just enter "C" (365 for days in a year, 300 for pick a number between 1 and 300) and then "D" (number of people) and find out your chances of 2 people having the same number:
#!/usr/bin/perl
$c=$ARGV[0];
$d=$ARGV[1];
while ($c eq "") {
print "Enter a number for C (e.g. 365 for bday bet): ";
chop($c=);
}
while ($d eq "") {
print "Enter a number for D ( number of people): ";
chop($d=);
}
#print "Using d = $d\n";
%numhash=();
$numerator=1;
$denominator=1;
$ctemp = 1;
$dtemp = 1;
#print "C: $c, D: $d;\n";
for ($ctemp = ($c - $d + 1); $ctemp <= $c; $ctemp++) {
# print "NUMERATOR: $numerator = $numerator * $ctemp\n";
$numerator *= $ctemp;
}
print "FINAL NUMERATOR: $numerator\n";
for ($dtemp=1;$dtemp <= $d; $dtemp++) {
# print "DENOMINATOR: $denominator = $denominator * $dtemp\n";
$denominator *= $c;
}
$b = 100*$numerator/$denominator;
$a = 100 - $b;
print "CHANCES: $a\n";
Sample runs:
[byau@netmanage01 byau]$ ./test2.pl 365 23
FINAL NUMERATOR: 4.22008193020924e+58
CHANCES: 50.7297234323985
This means with 23 people, 2 matches between 1 and 365 have a 50.7 percent change of hitting.
This means for the birthday bet: with 24 people, your chances of winning are 53.8%, with 25 people, your chances are 56.8%, and with 30 people, your chances are a whopping 70.6%!
[byau@netmanage01 byau]$ ./test2.pl 365 24
FINAL NUMERATOR: 1.44326802013156e+61
CHANCES: 53.8344257914529
[byau@netmanage01 byau]$ ./test2.pl 365 25
FINAL NUMERATOR: 4.92154394864862e+63
CHANCES: 56.8699703969464
[byau@netmanage01 byau]$ ./test2.pl 365 30
FINAL NUMERATOR: 2.17103018350856e+76
CHANCES: 70.6316242719269
Now let's use "300" as an example (i.e. telling people to choose a number between 1 and 300)
This means for picking a number between 1 and 300, with 15 people your chances are 29.9%, with 20 people: 47.6%, with 25 people: 64.2%, and with 30 people your chances are 77.7%!
[byau@netmanage01 byau]$ ./test2.pl 300 15
FINAL NUMERATOR: 1.00532372778665e+37
CHANCES: 29.9372608808011
[byau@netmanage01 byau]$ ./test2.pl 300 20
FINAL NUMERATOR: 1.82478203542775e+49
CHANCES: 47.6657623309199
[byau@netmanage01 byau]$ ./test2.pl 300 25
FINAL NUMERATOR: 3.02975058792369e+61
CHANCES: 64.2418114187157
[byau@netmanage01 byau]$ ./test2.pl 300 30
FINAL NUMERATOR: 4.59399985361917e+73
CHANCES: 77.6872378772132
Hey, maybe I'll put working interactive versions of the above scripts in the Fun Stuff area of our site.
Hmmm.. then again, if I do that, then my geekiness is REALLY out in the open, and I don't know if I'm ready for that yet because Sheri still thinks of me as a really cool stud-muffin.
Anyhow, happy betting! ...er... happy party-trick playing!!
Your Comments And Questions:
| Current Discussion: | ||
|
(no comments have been made yet for this article) |
More Articles? Look in the One2Swing Daily Archives
Want to stay informed? Subscribe to our mailing list!

