#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <math.h>
int f1(){
return rand()%4; // 1/4 chance
}
int f2(){
return rand()%50; // 1/50 chance
}
int f3(){
return rand()%100; // 1/100 chance
}
int main(){
double total[3] = {0.0},maxucb,newucb;
int tried[3] = {0};
int triedf = 0;
int i,j,n,maxind;
srand(time(NULL));
int (*f[3])() = {f1,f2,f3};
for(j=0;j<3;j++){
if(f[j]() == 0) total[j]+=1;
tried[j]++;
triedf++;
}
for(i=0;i<10000;i++){
maxucb = total[0]/triedf + sqrt((2*(log(triedf)))/tried[0]);
maxind = 0;
for(n=1;n<3;n++){
newucb = total[n]/tried[n] + sqrt((2*(log(triedf)))/tried[n]);
if(newucb > maxucb){
maxucb = newucb;
maxind = n;
}
}
if(f[maxind]() == 0) total[maxind]+=1;;
triedf++;
tried[maxind]++;
}
for(n=0;n<3;n++){
printf("win percentage: %f tries: %d\n",total[n]/tried[n],tried[n]);
}
system("pause");
return 0;
}