473,320 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Birthday Problem

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
bithdays 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[i]=rand()%365+1;
//cout<<" "<<sample[i];
a = sample[i];
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,

Thanks,

Sandra
Jul 22 '05 #1
58 7334
Sandra writes:
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
bithdays to match, but that is not the same thing :)

Here is what I have so far: <snip> 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 ?


You are off to a bad start. There are two ways to approach this, simulate
it and compute it. I think your instructor want you to compute it and you
are simulating.

Given a bazillion people in a room.
The fist person will not match anyone. The next person will have a
*different* birthday with probability 364/365. The next 363/365. And so on.

Now write a program, monitoring for the 95% threshold as you go. I think
there is an algorithm *too* but I don't think that is wanted here.

Yes, there is an exact answer to the question posed.
Jul 22 '05 #2
"Sandra" <s.********@mindspring.com> wrote
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 bithdays 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[i]=rand()%365+1;
//cout<<" "<<sample[i];
a = sample[i];
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..


This is a problem that should be solved analytically rather than with brute
force, unless you were specifically told to use brute force. If it's the
latter, consider a naive way to do it by hand: check the probability if the
group is of size 1. Then check if the group is of size 2. And so on, until
you hit 95%. There are more sophisticated ways to search that space, but
you're better off taking things one step at a time (no pun intended). Again,
if you have a choice, solve it analytically (any beginning text on
probabilities will have that very example).

Claudio Puviani
Jul 22 '05 #3
"osmium" <r1********@comcast.net> wrote in message
news:c5***********@ID-179017.news.uni-berlin.de

Given a bazillion people in a room.
The fist person will not match anyone. The next person will have a
*different* birthday with probability 364/365. The next 363/365. And
so on.

Right answer to the wrong question.

--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)
Jul 22 '05 #4
Sandra <s.********@mindspring.com> spoke thus:
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
As I said - just need some hints to move along..


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;
}

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #5
John Carson wrote:
"osmium" <r1********@comcast.net> wrote in message
news:c5***********@ID-179017.news.uni-berlin.de
Given a bazillion people in a room.
The fist person will not match anyone. The next person will have a
*different* birthday with probability 364/365. The next 363/365. And
so on.


Right answer to the wrong question.


It's Step One of a correct solution.

--
Regards,
Buster.
Jul 22 '05 #6
Christopher Benson-Manica <at***@nospam.cyberspace.org> spoke thus:
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 ;)


Holy cow, maybe I should go to lunch and get some blood sugar back in
me - that code is REALLY wrong!!! I guess on the bright side I don't
have to feel guilty about giving you undue help... I'd post something
closer to the correct answer, but I don't think I trust myself after
that egregious blunder. Sorry :(

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #7
Sandra wrote:

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


Are you supposed to calculate the answer, or (simulated) empirically
determine? From the looks of your code, it looks like you are going the
empirical route.
Jul 22 '05 #8
* s.********@mindspring.com (Sandra) schriebt:
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 think it would be better if you posted the exact assignment, because
as stated there is nothing involving C++ or even programming. With n
persons in the room the chance that none of them matches your birthday
is simply (364/365)^n (you need to think of it this way to get logical
"and" for simple multiplication of probabilities), so the chance that at
least one of them match is <censored/>; with the treshold at 0.95 that
gives 0.95 = <censored/> thus n = <censored/> ~= 1091.94. Thus
#include <iostream>
int main() { std::cout << 1092 << std::endl; }
would be one solution program, or perhaps
#include <iostream>
int main() { std::cout << 1091 + 1 << std::endl; }
if the text requires "computation", but I can't imagine that's what the
problem is about.

So please do post the exact assignment text.

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

Here is what I have so far:
#include "stdafx.h"
You absolutely don't need that.

#include <time.h>
In C++ write
#include <ctime>
but you don't need that either, unless it's really a requirement to use
Monte Carlo method or some such.

#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])


In standard C++ this is not a valid 'main' function. In standard
C++ one possible declaration of the 'main' function is
int main()
As for the rest of the code, as others have replied it's doubtful
that the intention is to do a simulation.

But that of course depends on the exact text of the assignment.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #9
Sandra writes:
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 ?


There is not any exact answer by using the Monte Carlo simulation you are
started on. You could compute till doomsday and you still wouldn't have an
exact answer. That's one reason why analysis is preferred to simulation in
simple problems such as this. Also, simulation doesn't give you much in the
way of insight into the problem and what a a good solution might be. In
general, in real problems, simulation is much easier than analysis.
Jul 22 '05 #10
Christopher Benson-Manica <at***@nospam.cyberspace.org> spoke thus:
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 ;)


FWIW, here is something that might actually compute the correct
answer. Yeesh, Mondays...

#include <iostream>

using namespace std;

int main(void)
{
int i=366; // includes February 29
double numerator=i, denominator=i;
while( numerator/denominator > .05 ) {
numerator*=--i;
denominator*=366;
}
cout << "The number is " << 366-i+1 << "\n";
return 0;
}

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #11
* Christopher Benson-Manica <at***@nospam.cyberspace.org> schriebt:

FWIW, here is something that might actually compute the correct
answer. Yeesh, Mondays...


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

I shall not call you an idiot, moron, etc., here.

But I reserve the right to hold that opinion, and be advised that's the
opinion most will (very privately) have on seeing such a posting.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #12
Alf P. Steinbach <al***@start.no> spoke thus:
Please DO NOT post what you think is a complete answer to someone
else's homework problem.
But I don't think it's complete - it solves a subtly different
problem, and perhaps a really different problem :)
But I reserve the right to hold that opinion, and be advised that's the
opinion most will (very privately) have on seeing such a posting.


I would hope that if I'm annoying people, they'd just tell me - I'm
very bad at catching subtle hints :(

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #13
* Christopher Benson-Manica <at***@nospam.cyberspace.org> schriebt:

I would hope that if I'm annoying people, they'd just tell me - I'm
very bad at catching subtle hints :(


You can be sure that at least I will be very clear about such things... ;-)

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #14
Alf P. Steinbach <al***@start.no> spoke thus:
You can be sure that at least I will be very clear about such things... ;-)


And I won't mind it a bit :)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #15
> 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
bithdays to match, but that is not the same thing :)

Here is what I have so far:


#include <math.h>
#include <iostream>

const bool i_am_born_on_feb_29 = false;

int main() {
std::cout << (int)std::ceil(std::log(0.05) /
(std::log(i_am_born_on_feb_29 ? 365.0 : 364.25) - std::log(365.25)));
}
Jul 22 '05 #16
* "Erik" <no@spam.com> schriebt:
...


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

Be advised most people, on seeing such a posting, will think of you as an
an uncaring Swedish idiot -- and certainly I do.

Perhaps that's why you're posting anonymously?

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #17
"Buster" <no***@nowhere.com> wrote in message
news:c5**********@newsg4.svr.pol.co.uk
John Carson wrote:
"osmium" <r1********@comcast.net> wrote in message
news:c5***********@ID-179017.news.uni-berlin.de
Given a bazillion people in a room.
The fist person will not match anyone. The next person will have a
*different* birthday with probability 364/365. The next 363/365.
And so on.


Right answer to the wrong question.


It's Step One of a correct solution.

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

--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)

Jul 22 '05 #18
> Please DO NOT post what you think is a complete answer to someone
else's homework problem.
I don't think his teacher will accept that answer, unless he's studying
mathematics, in which case he probably wouldn't ask in this NG.

If he can't solve a problem like that analytically, he will most definitely
fail his mathematics classes.

And if he does hand in my suggestion, the teacher will hopefully learn
from his mistake and create a more meaningful question for next year
(one that can't be more easily solved using mathematics than programming).
I guess this assignment was part of the first programming class, in which
it is important to show the students what programming can be used for,
not teach more complex methods to solve simple mathematical problems.

However, I did give him one hint (that he must handle the Feb 29 case).
Be advised most people, on seeing such a posting, will think of you as an
an uncaring Swedish idiot -- and certainly I do.

You can see me as anything you want to, but not many others do.
Perhaps that's why you're posting anonymously?


That's more of a religious issue. I don't like giving out my name, and
certainly not my email address, on the internet.
Jul 22 '05 #19
* "Erik" <no@spam.com> schriebt:
Please DO NOT post what you think is a complete answer to someone
else's homework problem.
I don't think his


Are you sure that Sandra is a "he"?

teacher will accept that answer, unless he's studying
mathematics, in which case he probably wouldn't ask in this NG.
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
Did you read the FAQ before posting,
<url: http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2>
as you're required to do?

Perhaps your English is not quite up to the task? What kinds of
moron students are they admitting these days at Lund's?

I don't like giving out my name, and certainly not my email address,
on the internet.


That's quite understandable.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #20
> > > Please DO NOT post what you think is a complete answer to someone
else's homework problem.
I don't think his


Are you sure that Sandra is a "he"?


Who cares?
teacher will accept that answer, unless he's studying
mathematics, in which case he probably wouldn't ask in this NG.


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?
Jul 22 '05 #21
On Mon, 12 Apr 2004 17:13:27 +0000 (UTC) in comp.lang.c++, Christopher
Benson-Manica <at***@nospam.cyberspace.org> wrote,
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?

Jul 22 '05 #22
* "Erik" <no@spam.com> schriebt:
> Please DO NOT post what you think is a complete answer to someone
> else's homework problem.

I don't think his
Are you sure that Sandra is a "he"?


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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #23
"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in
message news:c5**********@chessie.cirr.com...
Sandra <s.********@mindspring.com> spoke thus:
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
As I said - just need some hints to move along..


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.
--
Gary
Jul 22 '05 #24
John Carson wrote:
"Buster" wrote
John Carson wrote:
"osmium" wrote

Given a bazillion people in a room.
The fist person will not match anyone. The next person will have a
*different* birthday with probability 364/365. The next 363/365.
And so on.

Right answer to the wrong question.


It's Step One of a correct solution.


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.

--
Regards,
Buster.
Jul 22 '05 #25
"Buster" <no***@nowhere.com> wrote in message
news:c5**********@news6.svr.pol.co.uk

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.

--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)
Jul 22 '05 #26
David Harmon <so****@netcom.com> spoke thus:
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.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #27
Gary Labowitz <gl*******@comcast.net> spoke thus:
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.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #28
Buster <no***@nowhere.com> spoke thus:
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?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #29
John Carson writes:
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.


Paris in the
the spring.

Damn!

Jul 22 '05 #30

"Alf P. Steinbach" <al***@start.no> wrote in message
news:40****************@news.individual.net...
* "Erik" <no@spam.com> schriebt:
> > Please DO NOT post what you think is a complete answer to someone > > else's homework problem.
>
> I don't think his

Are you sure that Sandra is a "he"?
Who cares?


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.
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"?


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.
Jul 22 '05 #31
Sandra wrote:
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[i]=rand()%365+1;
//cout<<" "<<sample[i];
a = sample[i];
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

Jul 22 '05 #32

"Sandra" <s.********@mindspring.com> wrote in message
news:40**************@news.east.earthlink.net...
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...).
Jul 22 '05 #33
* "E. Robert Tisdale" <E.**************@jpl.nasa.gov> schriebt:


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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #34

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

On Mon, 12 Apr 2004 20:31:08 GMT, "Anonymous" <ih*******@nowhere.com>
wrote:

"Sandra" <s.********@mindspring.com> wrote in message
news:40**************@news.east.earthlink.net.. .
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...).


Jul 22 '05 #35
Something that calls itself Anonymous wrote:

[snip]

This is an obvious troll. Please ignore it.

Jul 22 '05 #36
Alf P. Steinbach wrote:

[snip]

Go away troll.

Jul 22 '05 #37
John Carson wrote:
"Buster" <no***@nowhere.com> wrote
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.


You're right.

--
Regards,
Buster.
Jul 22 '05 #38
Please don't top-post.

* s.********@mindspring.com (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: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #39
Please don't top-post.

* s.********@mindspring.com (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.]

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #40
On Mon, 12 Apr 2004 23:21:26 GMT, al***@start.no (Alf P. Steinbach)
wrote:


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: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Thanks Alf - I am working on an encyrption\decryption program right
now so I think I am going to let this one go. I really am stuck :)

He is going to give us the answer on Wed - Do you want to see what he
comes up with ?

Sandra
Jul 22 '05 #41

"David Harmon" <so****@netcom.com> wrote in message
news:40***************@news.west.earthlink.net...
On Mon, 12 Apr 2004 17:13:27 +0000 (UTC) in comp.lang.c++, Christopher
Benson-Manica <at***@nospam.cyberspace.org> wrote,
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?


Actually, the original question is unanswerable!

It would seem that there are four answers to the original question, one for
each of the following conditions:

1) Not a leap year, my birthday not on Feb. 29th.
2) Leap year, my birthday not on Feb. 29th.
3) Not a leap year, my birthday on Feb. 29th.
4) Leap year, my birthday on Feb. 29th.

We would need to handle "my birthday on Feb. 29th" differently from "my
birthday not on Feb. 29th", because the odds of someone ELSE having that
birthday are not the same as them having any other specific birthday. And
we'd have to handle the fact that it's leap year NOW because of the
differing number of days in the year.

However...

Even that is not accurate, because there is a basic assumption that the
distribution of birthdays across the year is uniform, and that is not a
provable assumption! (It may in fact be a false assumption, but I wouldn't
know how prove *that*, one way or the other.)

I *do* know that, for any given population, the distribution of birthdays is
not uniformly distributed. Look it up. If I recall, in temperate climates
there tend to be more births around the end of summer, presumably because as
it gets cold outside, people tend to, shall we say, "come together" more,
for the sake of warmth. And so, nine months later, there are more births.

So, if you live in a temperate climate, your birthday is in September, the
odds are greater that someone in a given set of people will have that
birthday than if your birthday is in, say April (where conception would have
occurred in July).

Of course, the instructor may have assumed a uniform distribution, and
intended to ignore leap year and a Feb. 29th birthday altogether. But,
being the nuisance I am, I'd have gone to the teacher and asked. :-)

-Howard




Jul 22 '05 #42
On 12 Apr 2004 19:33:45 EDT, "Howard" <al*****@hotmail.com> wrote:

"David Harmon" <so****@netcom.com> wrote in message
news:40***************@news.west.earthlink.net. ..
On Mon, 12 Apr 2004 17:13:27 +0000 (UTC) in comp.lang.c++, Christopher
Benson-Manica <at***@nospam.cyberspace.org> wrote,
> 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?


Actually, the original question is unanswerable!

It would seem that there are four answers to the original question, one for
each of the following conditions:

1) Not a leap year, my birthday not on Feb. 29th.
2) Leap year, my birthday not on Feb. 29th.
3) Not a leap year, my birthday on Feb. 29th.
4) Leap year, my birthday on Feb. 29th.

We would need to handle "my birthday on Feb. 29th" differently from "my
birthday not on Feb. 29th", because the odds of someone ELSE having that
birthday are not the same as them having any other specific birthday. And
we'd have to handle the fact that it's leap year NOW because of the
differing number of days in the year.

However...

Even that is not accurate, because there is a basic assumption that the
distribution of birthdays across the year is uniform, and that is not a
provable assumption! (It may in fact be a false assumption, but I wouldn't
know how prove *that*, one way or the other.)

I *do* know that, for any given population, the distribution of birthdays is
not uniformly distributed. Look it up. If I recall, in temperate climates
there tend to be more births around the end of summer, presumably because as
it gets cold outside, people tend to, shall we say, "come together" more,
for the sake of warmth. And so, nine months later, there are more births.

So, if you live in a temperate climate, your birthday is in September, the
odds are greater that someone in a given set of people will have that
birthday than if your birthday is in, say April (where conception would have
occurred in July).

Of course, the instructor may have assumed a uniform distribution, and
intended to ignore leap year and a Feb. 29th birthday altogether. But,
being the nuisance I am, I'd have gone to the teacher and asked. :-)

-Howard

Thanks Howard ~ I did ask him, he is not giving any clues except that
the number is exact and is between 1600-1700

I did not think there could be an exact answer either - just an
approximation

I guess I'll find out later this week - I will let you guys know what
he came up with

Sandra



Jul 22 '05 #43
Sandra <s.********@mindspring.com> spoke thus:
Thanks Howard ~ I did ask him, he is not giving any clues except that
the number is exact and is between 1600-1700
Well, at least Alfred's contention that I gave you the answer is
clearly wrong in that case ;)
I guess I'll find out later this week - I will let you guys know what
he came up with


Sounds like it has a definite trick question element to it.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #44
Sandra <s.********@mindspring.com> spoke thus:
He is going to give us the answer on Wed - Do you want to see what he
comes up with ?


Given the level of discussion, I doubt he'd be the only one :)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #45
On Mon, 12 Apr 2004 23:59:55 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.cyberspace.org> wrote:
Sandra <s.********@mindspring.com> spoke thus:
Thanks Howard ~ I did ask him, he is not giving any clues except that
the number is exact and is between 1600-1700


Well, at least Alfred's contention that I gave you the answer is
clearly wrong in that case ;)
I guess I'll find out later this week - I will let you guys know what
he came up with


Sounds like it has a definite trick question element to it.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.


I will let you guys know :)
Jul 22 '05 #46
"Sandra" <s.********@mindspring.com> wrote in message
news:40**************@news.east.earthlink.net...
On Mon, 12 Apr 2004 23:21:26 GMT, al***@start.no (Alf P. Steinbach)
wrote:


Well, it seems your work is cut out for you, unless the context of theproblem 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 February29th, and then apply the formula inconsiderately given you by RobertE. Tisdale and at least one more poster. The program could output oneresult based on the current year or on assuming a non leap-year, or it couldoutput two result, one for non-leap and one for leap-year. In the latter casethe formula should be suitably modified for leap year. Of course it couldalso output four results, one for each combination of February 29th or not andleap year or not. That way you could avoid the input part.

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

--
A: Because it messes up the order in which people normally read text.Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Thanks Alf - I am working on an encyrption\decryption program right
now so I think I am going to let this one go. I really am stuck :)

He is going to give us the answer on Wed - Do you want to see what

he comes up with ?


You bet. Especially since you cannot know, without some distribution
information, how many people it will take to find your birthday.
If you were born on 1-1 and asked people as they got off the subway if
anyone was born on 1-1 there is no telling how many people you would
ask before one of them was born on 1-1. It's not the pigeon hole
principle here. You might go through 1,000,000 people until one was
born on 1-1. There is just no way of telling.
If, on the other hand, you were asking people what their birthdates
were and kept track of the answers, you might be surprised to find
that after the first 20 you will have a 50-50 chance of finding two of
them with the same birthday. But it is a different problem.

I think your teacher is on a wrong track.
--
Gary (who was a math major, but not really very good at statistics)
Jul 22 '05 #47
* Christopher Benson-Manica <at***@nospam.cyberspace.org> schriebt:
Sandra <s.********@mindspring.com> spoke thus:
Thanks Howard ~ I did ask him, he is not giving any clues except that
the number is exact and is between 1600-1700


Well, at least Alfred's contention that I gave you the answer is
clearly wrong in that case ;)


The only meaningful numerical result is the one I gave first, and implied by
later posters. Sandra would not have learned less if you just gave that
number. What one should not do is to help someone avoid learning, or,
although clearly not the case here, to cheat.

I guess I'll find out later this week - I will let you guys know what
he came up with


Sounds like it has a definite trick question element to it.


I think so too. The range 1600-1700 means the seemingly only meaningful
result (for non Feb 29) is not the one intended. I'm leaning towards thinking
there is some earlier context -- earlier questions -- Sandra did not list.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #48
On Mon, 12 Apr 2004 15:41:39 GMT, s.********@mindspring.com (Sandra)
wrote:
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


This question is impossible to answer without statistics on how many
people in the population were born on each day of the year. It is very
unlikely to be a uniform distribution, which is what everyone else
seems to be assuming (e.g. if everyone in the world was born on 4th
July, the answer would be 1).

Even if you assume that anyone was born on a particular day of the
year with equal probability, you still run into the problem of leap
years. To calculate how this affects things will require a full world
population age distribution, to find out the average number of leap
years per year over the population as a whole. However, assuming
365.25 days per year is probably safe since you only need a result to
the nearest person.

Anyway, before answering the question, make sure you state your
assumptions clearly.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #49
"Sandra" <s.********@mindspring.com> wrote in message
news:40**************@news.east.earthlink.net...
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 do not think that the data you provided are enough. When you say birthday
you mean day and month and year? Is there any other restriction (e.g. is it
possible two people in the room to have the same birthday (day, month and
year) and still be different from yours?



--
Ioannis Vranos

Jul 22 '05 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Sandra | last post by:
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.