Posts

Showing posts with the label probability

Exactly one high card in a 6 card hand using simulations

Image
Exactly one high card in a 6 card hand using simulations So I've got a probability problem that (out of pure boredom) I decided to try and solve using simulations. Problem: What is the probability of drawing exactly one high card in a 6 card hand. Now, this problem is specifically about some game that's played in my country so for some weird reason there are 21 high cards, but that's not important. Solving this problem by hand, using basic combinatorics I got: And now, here's the way I simulated it in C: The main function: int main(void) { srand(time(0)); int deck[52]; int i; for(i = 0; i<21; i++) deck[i] = 1; for(i = 21; i<52; i++) deck[i] = 0; int n; printf("# of simulations: "); scanf("%d", &n); int memo[52]; int hits = 0; for(i = 0; i<n; i++){ clear_memo(memo); hits += simulate(deck, memo); } printf("Result: %lfn", (double)hits/n); } So the deck is an array of...