[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Quick /g/! Write a Java program that finds, on average, the amount

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 25
Thread images: 5

File: apt6jrkndapqhkjraon4.jpg (87KB, 800x450px) Image search: [Google]
apt6jrkndapqhkjraon4.jpg
87KB, 800x450px
Quick /g/! Write a Java program that finds, on average, the amount of people you would need to poll before you found one with the same birthday as another person already polled, or this bird will kill you!
>>
The year doesn't matter, just the date.
>>
File: 170x170bb.jpg (5KB, 170x170px) Image search: [Google]
170x170bb.jpg
5KB, 170x170px
b-b-b-b-bump
>>
>>58345794
Why is there a ziptie around the birds leg?
>>
File: 1476911861456.jpg (88KB, 1000x841px) Image search: [Google]
1476911861456.jpg
88KB, 1000x841px
>>58345854
WRONG
>>
See my shitty code and laugh. Every time I run it it's [spoiler]24[/spoiler] people.

 
Random rand = new Random();
ArrayList<Integer> list = new ArrayList<Integer>();
Set<Integer> set = new HashSet<Integer>();
for (int i = 0; i < 50000; i++) {
int count = 0;
while (true) {
int temp = rand.nextInt(365);
count++;
if (set.contains(temp))
break;
set.add(temp);
}
set.clear();
list.add(count);
}
// System.out.println(list);
int sum = 0;
for (int num : list) {
sum += num;
}
System.out.println(sum / list.size() + " people average");
>>
>>58346401
Oops, no spoilers on /g/. Well whatever.
>>
>>58345794
>sol1
google birthday problem and give solution
>sol2
use pigeonhole principle and give answer
God why am i on this childish shithole? im a software engineer and still browsing this inane site back when i was 12
>>
>>58345794
You don't even need a computer program for that. Its equal to half the days in a year if each day is equally likely to have a birthday on it.
>>
>>58348699
Read the question again.
>>
>>58348719
At the halfway point the probability of getting a person with the same birthday as one already polled flips into favoring a pre polled birthday from a new one. If each day is equally likely that a person was born on it then as the number of trials tends to infinity, the average number of people to find one with the same birthday as one previously polled approaches half the amount of days in a year. Additionally as you approach 365 people polled the probability of getting one with a birthday already seen approaches 1 in 1.
>>
>>58345794
10 PRINT HACK THE PLANET
20 GOTO 10
>>
>>58348719
As an aside note you'll find that in real life the number is actually MUCH MUCH lower than half the number of days in the year owing to the fact that the most people are born in June (I believe I haven't checked it in a long time) and very few people are born in February and January. So once you survey someone born in the most common month your chances of surveying someone with the same birthday as a previously polled person skyrockets.
>>
File: _0a1479443488641.png (565KB, 1181x1113px) Image search: [Google]
_0a1479443488641.png
565KB, 1181x1113px
>>58348777
>>
>>58348762
>the average number of people to find one with the same birthday as one previously polled approaches half the amount of days in a year
So you're saying on average it will take 182.5 people before one will have the same birthday as another one. Maybe there's something I'm not getting here but I really don't think this is true.

>>58348830
Good point.
>>
>>58348762
https://en.m.wikipedia.org/wiki/Birthday_problem
>not knowing about the birthday problem
>>
>>58348879
It is true given an imaginary world where people are equally likely to be born on each day. Check my math.

Where:

a is the number is people polled
b is the number of days of the year polled
c is the probability of a person having the same birthday as another
d is the probability of pulling a person that doesn't have a birthday we have already

c = a/365
d = (365-b)/365

if a >= 365/2 then c >= 1/2

as c approaches 1 b approaches 365 and d approaches 0;

Since we stop trials when we get a duplicate birthday and as c increases we have a higher chance of getting a duplicate we can consider the median of c as the average since c is linear. I'm not sure how else to break this down. Maybe I am making a mistake but i don't see it. It makes perfect sense to me.
>>
>>58348762
Let's start by polling one person, he tells you his birth date

You poll another one, that's a 1/365 chance the birth date will be the same

You poll next one, now there's a 2/365 chance the birth date will match one of the previous ones

Another one, 3/365 chance

Polling just 25 people you already have a (25 * 25/365) / 2 = 85.6% chance that you'll have a match
>>
>>58349043
Ah I see now. I was wrong. Thank you.
>>
>>58345794
so following up on this >>58349043, you should need to ask ~28 people to have a match if I'm not mistaken
>>
>>58349043
Isn't it a n!/365 chance, though?
>>
>>58349245
I looked it up on wikipedia and it's 23 actually.

My code in >>58346401 should have the "if (set.contains(temp)) break;" and "count++" reversed in order, and it gets 23 if you do switch those lines.
>>
>>58349012
You must take the discrepancy into account, say more people being born 9 months from a vacation like new year etc
>>
What a stupid probability problem
>>
File: 1480294469694.png (157KB, 800x600px) Image search: [Google]
1480294469694.png
157KB, 800x600px
>>58349671
Better or worse than this?
Thread posts: 25
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.