[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math

Search:


View post   

>> No.7979797 [View]
File: 12 KB, 579x368, chanball.gif [View same] [iqdb] [saucenao] [google]
7979797

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int main(void)
{
int N=1000000,n,randbox,randball,otherball,m=0,M=0;
int boxes[3][2]={{1,1},{1,0},{0,0}}; /* 1=gold, 0=silver */

for(n=0;n<N;n++)
{
randbox=rand()%3; /* pick a random box */
randball=rand()%2; /* pick a random ball */
if (boxes[randbox][randball]==0) continue;
M++; /* count times we got a gold ball */
otherball=1-randball;
if (boxes[randbox][otherball]==1) m++;
}
printf("m:%d M:%d prob:%f\n",m,M,m/(double)M);
return(0);
}
gives
m:333143 M:499928 prob:0.666382

So in a million tests, we get a gold ball on the first draw about 50% of the time. Makes sense since 3 of the 6 balls are gold. Of those times when we first draw a gold ball, about 2/3rd of the time our second draw is gold.

The answer: 2/3.

Navigation
View posts[+24][+48][+96]