#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#define NUMTRIALS 1000000
#define N 100
#define R 3

int trial(int r, int b);

int main() {

    srand(time(0));

    int loop;
    double sum = 0;
    for (loop=0; loop<NUMTRIALS; loop++)
        sum += trial(R, N-R);

    printf("Experimental Average was %.3lf\n", sum/NUMTRIALS);

    return 0;
}

int trial(int r, int b) {

    int n = r+b, turns = 0;

    while (r > 0) {
        int x = rand()%n;
        if (x < r) r--;
        turns++;
    }

    return turns;

}
