Created
November 20, 2016 08:31
-
-
Save ryanmjacobs/d66510ce160d0e9f4ec29d99c50ae3d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define NUM_TRIALS 1e9 | |
int randint(int n); | |
unsigned int play(void); | |
int main(void) { | |
srand(time(NULL)); | |
unsigned long long int total = 0; | |
for (int i = 0; i < NUM_TRIALS; i++) { | |
total += play(); | |
} | |
printf("average win: %0.2f\n", total/NUM_TRIALS); | |
return 0; | |
} | |
unsigned int play(void) { | |
unsigned int pot = 1; | |
while (rand() % 2 == 0) | |
pot *= 2; | |
return pot; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment