473,425 Members | 1,703 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,425 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
58 7353
Alf P. Steinbach <al***@start.no> spoke thus:
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 certainly hope I did neither...

--
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 #51
Sandra wrote:
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.


Is that _birthday_ as in sharing a common day of the year

- or -

_birth_date_ as in sharing a common point in time (day, month, year)?
Jul 22 '05 #52

"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:40************@jpl.nasa.gov...
Something that calls itself Anonymous wrote:

[snip]

This is an obvious troll. Please ignore it.


I actually find this offensive. I have never been called a troll before
and I don't understand why my post was considered one.
It was polite (no insults of any kind) and not only did it simply say
that this was not an appropriate place for the question but it also
suggested other groups where it would be more appropriate. I mean, while
any of us are capable of helping her with this problem, it was a math
problem that really didn't have anything to do with C++ or even programming!
Really, where is the C++ in "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?"
Jul 22 '05 #53
Anonymous <ih*******@nowhere.com> spoke thus:
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
(drivel)
I actually find this offensive. I have never been called a troll before
and I don't understand why my post was considered one.


Most regulars of this group (and comp.lang.c) realize that E. Robert
Tisdale is a troll himself. His opinions on who is or is not a troll
are fairly irrelevant; please try not to take his trolls seriously or
personally.

--
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 #54
"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
Sandra wrote:
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.


Is that _birthday_ as in sharing a common day of the year

- or -

_birth_date_ as in sharing a common point in time (day, month, year)?


It's an old logic puzzle. It refers to birthday - no year is implied.
You and I can share a birthday and be 20 years apart in age.
I think if you have 25 people the answer is something like a 50% chance.
By the time you have 70 people in a room it is about 100% - unless it's
a Twins convention! :)

Not what you thought, huh!
The way to get the actual number is to analyze what the probabilities
are. If I am in a room with just one person, then the chances of us
sharing a birthday are 1 in 365. Add another person and the probability
goes to 1 in 363. So, (364/365) x (363/365).

The complete table is an exercise for the student! ;-)

--
Mabden

Jul 22 '05 #55
Mabden <ma****@sbcglobal.net> spoke thus:
The way to get the actual number is to analyze what the probabilities
are. If I am in a room with just one person, then the chances of us
sharing a birthday are 1 in 365. Add another person and the probability
goes to 1 in 363. So, (364/365) x (363/365). The complete table is an exercise for the student! ;-)


Or an exercise for previous posts :) (It turns out that I was the one
who posted that code, and it also turns out that the professor is
looking for a vastly different answer.)

--
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 #56
> 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).


Interesting point ... in fact, in some areas, like say Minnesota or
North Dakota, birthdays tend to be clustered in the months July-Sept.

[ya' gotta find somethin' to do on those long, cold winter nights I
guess]

To extend this further, with technological advances in the last n
years (say 40 if you like), the "clustering" from the above example
has likely started to decrease with time, yielding a more even
distribution for people born more recently.

[Now you can drive in your heated automobile on plowed, paved roads
to, say, go bowling .. so there are more solutions to the
aforementioned "what to do" problem, regardless of the time of year
....]

So, you would really have to know quite a lot of details about the
people in the room (is it a geratrics convention in Alberta, or a
child's birthday party in Sao Paolo) in order to get an accurate grasp
on the probability problem.
Like some other posters in this thread, I wonder if the point of the
problem was really the code, or whether it was intended to help you
realize that sometimes the most simply stated problems are the
trickiest to solve. If I were the prof., I would give credit based
not so much on the code itself, but rather on how well the students
thought about the problem ... recognizing the leap-year issue gets one
point, the non-even birthday distribution gets two points, etc. After
all, a careful analysis of the problem is (at least) 80% of proper
program design .. I guess (from context) that your course is on an
introductory level, but one can never learn this lesson too early.

I am extremely interested to see the soln. given by your prof. ... if
only to find out how narrowly/broadly the problem was defined in her
mind. In my experience, profs, like wizards, can be quite subtyl ..
and they can even be quick to anger as well 8*).

Good luck!
Jul 22 '05 #57
Dave Moore wrote:
Interesting point ... in fact, in some areas, like say Minnesota or
North Dakota, birthdays tend to be clustered in the months July-Sept.

[ya' gotta find somethin' to do on those long, cold winter nights I
guess]

Do you have statistics to back that up? Sounds pretty urban-legendy to
me, like the supposed baby booms following blackouts and 9/11 and such.

Brian Rodenborn
Jul 22 '05 #58
Default User wrote:
Dave Moore wrote:

Interesting point ... in fact, in some areas, like say Minnesota or
North Dakota, birthdays tend to be clustered in the months July-Sept.

[ya' gotta find somethin' to do on those long, cold winter nights I
guess]



Do you have statistics to back that up? Sounds pretty urban-legendy to
me, like the supposed baby booms following blackouts and 9/11 and such.


Live birth totals for USA 1993 :

Month Per Vs daily
Total Day Avg

Jan 323,420 10,433 -4.91%
Feb 304,947 10,891 -0.73%
Mar 342,518 11,049 0.71%
Apr 327,372 10,912 -0.54%
May 336,368 10,851 -1.10%
Jun 335,703 11,190 +1.99%
Jul 352,949 11,385 +3.77%
Aug 351,306 11,332 +3.29%
Sep 348,399 11,613 +5.85%
Oct 333,313 10,752 -2.00%
Nov 316,751 10,558 -3.76%
Dec 331,477 10,693 -2.54%
Monthly totals from "Live births by state by month for 1993"
http://www.nber.org/natality/1993/docs/nat1393.txt

Interested people can repeat the calculations for individual states.

Jul 22 '05 #59

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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.