-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonties_auto_runner.c
73 lines (59 loc) · 1.91 KB
/
Monties_auto_runner.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Written By D-VR
Copyright 2018 GPL-2.0 license
Info About the Monty Hall Problem:
https://en.wikipedia.org/wiki/Monty_Hall_problem
Simulates Monty Halls Problem and always picks the option to 'Switch'
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{
int rndint, windoor, userdoor, HostDoor, choicedoor;
float gamecount = 0;
float wincount = 0;
float percantager = 0;
char newFrame[] = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
srand(time(NULL));
for (;;)
{
gamecount+=1;
rndint = rand() % 3;
windoor = rndint+1;
userdoor = rand() % 3;
userdoor+=1;
if((userdoor + windoor) == 4 && (userdoor != windoor)){
HostDoor = 2;
}
else
if((userdoor + windoor) == 5){
HostDoor = 1;
}
else
if((userdoor + windoor) == 3){
HostDoor = 3;
}
else
for(;;){
rndint = rand() % 3;
rndint+=1;
if(rndint != windoor){
HostDoor = rndint;
break;
}
}
choicedoor = 6 - HostDoor - userdoor;
if(choicedoor == windoor){
wincount+=1;
}
percantager = wincount / gamecount;
percantager*=100;
printf("%sMonty Hall - Always Switch\n\nCurrent Game: %.2f\nCurrent Amount of Wins: %.2f\nWin percentage: %.2f\n", newFrame, gamecount, wincount, percantager);
usleep(5000);
}
return 0;
}