-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoddeve.cpp
More file actions
49 lines (45 loc) · 912 Bytes
/
oddeve.cpp
File metadata and controls
49 lines (45 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
#define int long long
using namespace std;
int iterations = 1e5, score[2], chk=1e4;
int W = 1, N = 6;
int get0()
{
return 1 + rand()%N;
}
int get1()
{
return N;
}
void play(int plnum)
{
int wickets=0;
while(wickets<W)
{
int g[2] = {get0(), get1()};
if(g[0]==g[1]) wickets++;
else score[plnum]+=g[plnum];
}
}
signed main()
{
cout << setprecision(20);
double avg = 0;
int l2 = 0;
srand(time(NULL));
for(int i = 0; i < iterations; i++)
{
if(i && i%chk==0)
{
cout << 1 - (double) l2/chk << endl;
l2=0;
}
score[0]=score[1]=0;
play(0);
play(1);
// cout << score[0] << " " << score[1] << " - " << (score[0]>score[1]) << endl;
avg += (double) score[1]/score[0];
if(score[0]>score[1]) l2++;
}
cout << avg/iterations;
}