Birthday Problem

E

Erik

Please DO NOT post what you think is a complete answer to someone
Are you sure that Sandra is a "he"?

Who cares?
You're an idiot all right.

Did you notice that Sandra wrote


I am not asking for source code and I am not asking anyone to do
my homework as I do want to learn

If she gets a chance to get extra credit, she's probably supposed to
solve it by herself, so she deserves a stupid answer.
Perhaps your English is not quite up to the task?

Perhaps not, or it could be your brain. You cut out most of my mail
that explained why I wrote what I did. Didn't you understand that?
What kinds of moron students are they admitting these days at Lund's?

Too stupid ones, if you ask me. (BTW, was I supposed to be
impressed with you because you managed to find my location in the
headers). Do you often try to find out as much personal information
as possible about the people you disagree with? Shall I expect a dead
pigeon's head in my mailbox soon?
 
D

David Harmon

On Mon, 12 Apr 2004 17:13:27 +0000 (UTC) in comp.lang.c++, Christopher
Benson-Manica said:
int i=366; // includes February 29

I am sure it cannot be correct to give Feb 29 the same weight as all the
other days. Which is the closer approximation, to do as above or to
ignore Feb 29 and calculate using 365?
 
A

Alf P. Steinbach

* "Erik said:
Who cares?

Thank you. Have you considered that perhaps Sandra cares? I think
not, since not spotting something so basic indicates a dead brain.

she deserves a stupid answer.

Thank you.

BTW, was I supposed to be impressed with you because you managed to
find my location in the headers.

Thank you. On my screen your message displays with this prominently in
place at the top: "Lund Institute of Technology, Sweden". But perhaps
for you that's as difficult to spot as "Sandra"?

Do you often try to find out as much personal information
as possible about the people you disagree with?

Thank you, again.

Shall I expect a dead pigeon's head in my mailbox soon?

Urgh, my thank-you box is near empty, so. In the future, please DO NOT
post what you think is a complete solution to someone else's homework.
ESPECIALLY when the originally poster asks you not to do so.
 
B

Buster

John said:
Perhaps. Provided you are prepared to go around the world a couple of times
in order to get there.

Let p (n) be the probability that two or more people in a room have the
same birthday when n people are in the room.

"The first person will not match anyone."
Therefore the probability that all the birthdays are different is 1.
Therefore p (0) = 0;

"The next person will have a different birthday with probability
364/365."
Therefore the probability that all the birthdays are different is
1 * (364/365).
Therefore p (1) = 1 - (1 * (364/365)) = (1/365) < 95%.

"The next 363/365.".
Therefore, the probability that all the birthdays are different is
1 * (364/365) * (363*365).
Therefore, p (2) = 1 - (1 * (364/365) * (363 / 365)) < 95%.

In general, if there are n people in a room, the probability that
all the birthdays are different is /* */.
Therefore, p (n) = 1 - /* */.

This is the solution I was taught as an undergraduate.
 
G

Gary Labowitz

Christopher Benson-Manica said:
The following code, I believe, calculates the number of people that
must be in a room for there to be a 95% chance that at least two
people will have the same birthday - perhaps you can make use of the
general idea for your problem. Or perhaps I will prove to be very
wrong, in which case you should not listen to me ;)

#include <iostream>

using namespace std;

int main(void)
{
int i=366; // includes February 29
while( (float)i/(float) 366 > .05 )
i--;
cout << "The number is " << i << "\n";
return 0;
}

As a check to anything you code, I believe the number of people you
have to have such that any two of them have the same birthday is a 50%
probability is 20. This is a little different than exactly matching a
specified birthday, but it may give you some insight into how the
probability is calculated. This truly seems more like a math problem
to me. The kind of bonus work I give is: "Given three int's entered by
a user, determine the kind of triangle with those three sides in
length would be; equilateral, isosceles, or scalene. Can you tell if
the triangle is a right triangle?" This is for nested if's or switch's
structures. At least the math isn't hard.
 
J

John Carson

Buster said:
Let p (n) be the probability that two or more people in a room have
the same birthday when n people are in the room.

Like I said, the right answer to the wrong question. Here is the question
from the OP:

"Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday"

Whether other people in the room besides "me" have matching birthdays is
irrelevant.
 
E

E. Robert Tisdale

Sandra said:
I was given this problem for extra credit and I am just stuck !
BTW - I am not asking for source code and I am not asking anyone to do
my homework as I do want to learn .. I just need a hint or two to get
moving and I need to know if what I have written so far is leading me
in the right direction ~

Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday

I wrote a program that will calculate that percentage for any 2
birthdays to match, but that is not the same thing :)

Here is what I have so far:


#include "stdafx.h"
#include <time.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int sample[1000];
int i=1,j=1;
int a =0;
srand( (unsigned)time( NULL ) );

while (a != 325)
{ sample=rand()%365+1;
//cout<<" "<<sample;
a = sample;
i++;
if (a==325) cout<<"\n\n\n Match "<<a<<" at "<<i<<"\n";
}

return 0;

This puts random numbers from 1-365 in an array - reads the array and
tries to detect an exact match
The problem is that the match is so random - how do I come up with a
95% chance? Is there any exact answer ?

As I said - just need some hints to move along..

Any replies will be appreciated,


I think that the problem more simple than that.

You need to know how many N people there must be so that
the probability that *no* one has your birthday is just less that 5%.
The probability that another person chosen at random doesn't have
your same birthday is P = 364/365 (or, more accurately, 1457/1461).
Choose N so that

P^N < 5% = 5/100 < P^(N-1)

or

N-1 < log(5/100)/log(P) < N
 
C

Christopher Benson-Manica

David Harmon said:
I am sure it cannot be correct to give Feb 29 the same weight as all the
other days. Which is the closer approximation, to do as above or to
ignore Feb 29 and calculate using 365?

Hm, interesting point. Perhaps the real probabilities are

A day that is not February 29: 4/1461
February 29: 1/1461

I despised probability and statistics in school, so the probability of
the above being correct is probably not 1 ;) In any case, it should
give the OP food for thought...

P.S. Given the convoluted leap year rules, I'm actually quite certain
that the above is not correct; it's probably closer to the truth than
what I originally assumed, however.
 
C

Christopher Benson-Manica

Gary Labowitz said:
As a check to anything you code, I believe the number of people you
have to have such that any two of them have the same birthday is a 50%
probability is 20. This is a little different than exactly matching a
specified birthday, but it may give you some insight into how the
probability is calculated. This truly seems more like a math problem
to me. The kind of bonus work I give is: "Given three int's entered by

Notice that in a followup to my post to which you followed up, I
admitted that I had horribly botched the "solution" and amended it. I
got 47, which may or may not be correct.
 
C

Christopher Benson-Manica

Buster said:
Therefore, the probability that all the birthdays are different is
1 * (364/365) * (363*365).
Therefore, p (2) = 1 - (1 * (364/365) * (363 / 365)) < 95%.

What about leap year?
 
O

osmium

John said:
Like I said, the right answer to the wrong question. Here is the question
from the OP:

"Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday"

Whether other people in the room besides "me" have matching birthdays is
irrelevant.

Paris in the
the spring.

Damn!
 
E

Erik

Alf P. Steinbach said:
Thank you. Have you considered that perhaps Sandra cares? I think
not, since not spotting something so basic indicates a dead brain.

If Sandra is very angry with me about that, I will give her all my
apologies.
Thank you. On my screen your message displays with this prominently in
place at the top: "Lund Institute of Technology, Sweden". But perhaps
for you that's as difficult to spot as "Sandra"?

Well, on mine it doesn't, I have to click a button to see the header.
Now I see ABSOLUTELY no reason for you to ask those questions.
Urgh, my thank-you box is near empty, so. In the future, please DO NOT
post what you think is a complete solution to someone else's homework.
ESPECIALLY when the originally poster asks you not to do so.

Didn't you care to read my last post, or didn't you understand it?
I didn't post what I think is a complete solution.

I can't believe you can write, but you can't read.
 
A

Anonymous

Sandra said:
I was given this problem for extra credit and I am just stuck !
BTW - I am not asking for source code and I am not asking anyone to do
my homework as I do want to learn .. I just need a hint or two to get
moving and I need to know if what I have written so far is leading me
in the right direction ~

Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday

If I understand the problem, this is _absolutely_ the _wrong_ group to
post this question! This has nothing to do with programming, much less C++.
The best thing you can say about this problem is that you'll have to
implement the factorial function, or a variant, thereof.
A more appropriate place to post this would have been sci.math. I might
have even suggested alt.sci.math.probability, if it weren't for all the spam
that happens there (undoubtedly as a result of it being an alt.*
newsgroup...).
 
A

Alf P. Steinbach

Just for completeness, since I've responded to the others in this thread
doing the "Hey look I can solve novice homework problems!" as you now do:

Please DO NOT post what you think is a complete answer to someone
else's homework problem.

However, I think this advice (which is also in the FAQ, as well as in
Sandra's posting that you replied to) is wasted on you. It would be
nice if you proved me wrong. But I do not expect that from you.
 
E

E. Robert Tisdale

Something that calls itself Anonymous wrote:

[snip]

This is an obvious troll. Please ignore it.
 
S

Sandra

Gee thanks guys !

Erik -

#1 I am a Girl
#2 I did not deserve a STUPID answer

Alf -

Thank You for sticking up for me while I was away
I was brainblocked and just needed to know if I was
on the right track. The exact problem as given to me
states as below - yes this is a c++ class, the extra credit
problems are always fun ones ..

Extra Credit Problem ***

Write a C Program that will determine how many people must be in a
room in order to insure a 95% chance there is somebody in that room
with your birthday.


~~ I sold my damn statitics book 5 years ago (wish I hadn't now)

Robert -

Thank you - I think I understand now !

All - Looks like I caused an unintentional stir, I did not need code I
just needed some brain stimulation

Apologies,

Sandra
 
B

Buster

John said:
Like I said, the right answer to the wrong question. Here is the question
from the OP:

"Ok - The problem is to find out how many people need to be in a room
for a 95% chance that someone in that room will match my birthday"

Whether other people in the room besides "me" have matching birthdays is
irrelevant.

You're right.
 
A

Alf P. Steinbach

Please don't top-post.

* (e-mail address removed) (Sandra) schriebt:
Extra Credit Problem ***

Write a C Program that will determine how many people must be in a
room in order to insure a 95% chance there is somebody in that room
with your birthday.

Well, it seems your work is cut out for you, unless the context of the
problem formulation is such that it really means something more than stated.

All your program has to do is to ask you whether your birthday is February
29th, and then apply the formula inconsiderately given you by Robert
E. Tisdale and at least one more poster. The program could output one
result based on the current year or on assuming a non leap-year, or it could
output two result, one for non-leap and one for leap-year. In the latter case
the formula should be suitably modified for leap year. Of course it could
also output four results, one for each combination of February 29th or not and
leap year or not. That way you could avoid the input part.

Also, it might be possible to avoid the leap year thing by analyzing whether
it can affect the result or not.
 
A

Alf P. Steinbach

Please don't top-post.

* (e-mail address removed) (Sandra) schriebt:
Extra Credit Problem ***

Write a C Program that will determine how many people must be in a
room in order to insure a 95% chance there is somebody in that room
with your birthday.

Well, it seems your work is cut out for you, unless the context of the
problem formulation is such that it really means something more than stated.

All your program has to do is to ask you whether your birthday is February
29th, and then apply the formula inconsiderately given you by Robert
E. Tisdale and at least one more poster. In the case of February 29th the
formula should be suitably modified. But it might be possible to avoid all
that by analyzing whether it can affect the result or not.

Also, it is possible to avoid the input part by having the program
output two results, one for February 29th and one for any other birthday.



[Note: an earlier version of this message, with extremely faulty logic (late
night hurry), was posted and immediately cancelled, but might still have made
it to your newsserver -- if so just ignore it.]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top