Re: Birthday Problem
From: Claudio Puviani (puviani_at_hotmail.com)
Date: 04/12/04
- Next message: John Carson: "Re: Birthday Problem"
- Previous message: osmium: "Re: Birthday Problem"
- In reply to: Sandra: "Birthday Problem"
- Next in thread: Christopher Benson-Manica: "Re: Birthday Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 12 Apr 2004 15:52:58 GMT
"Sandra" <s.cantrell@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
- Next message: John Carson: "Re: Birthday Problem"
- Previous message: osmium: "Re: Birthday Problem"
- In reply to: Sandra: "Birthday Problem"
- Next in thread: Christopher Benson-Manica: "Re: Birthday Problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|