Skip to content

Instantly share code, notes, and snippets.

@emctague
Created June 25, 2020 05:13
Show Gist options
  • Save emctague/a2f77e4feca796df6febdaf2ee166592 to your computer and use it in GitHub Desktop.
Save emctague/a2f77e4feca796df6febdaf2ee166592 to your computer and use it in GitHub Desktop.
MHall
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(NULL));
int allTries = 1000;
int switchWins = 0;
for (int i = 0; i < allTries; i++)
switchWins += (rand() % 3) != (rand() % 3);
printf(" Wins\t%% Wins\n");
printf("Switch: %d\t%f%%\n", switchWins, (float)switchWins / (float)allTries * 100.f);
printf(" Don't: %d\t%f%%\n\n", allTries - switchWins, (float)(allTries - switchWins) / (float)allTries * 100.f);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment