A friend of mine was making an omelet and found 3 double-yolk eggs in the box. What is the probability of that happening? (assume only 1 out of every 100 eggs is double-yolk)

**Answer: ** 0.000205616 (probability of seeing 3 or more double-yolk eggs in a box)

Let’s make this question more interesting by changing it to: “what is the probability of having at least 2 double-yolk eggs in a box of dozen?”. For this, it would be in fact easier to find the probability of having only 1 or no double-yolk eggs in the box and then calculate one minus that probability.

In the general form, if we want to have at least a minimum number of double-yolk eggs we can arrive at the following formula using the Binomial distribution:

If you solve this you will arrive at 0.000205616 as the answer.

To be sure that this formula is correct I wrote a little c++ code that could simulate this process. The results from the theoretical formula matches the simulation results.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
#include <iostream> #include <stdlib.h> #include <time.h> #include <iomanip> #include <math.h> using namespace std; long factorial(int _x) { long factorialValue = 1; for (int i=1; i<=_x; i++){ factorialValue = factorialValue * i; } return factorialValue; } int combination(int _N, int _n) { return factorial(_N)/(factorial(_n)*factorial(_N -_n)); } double calculateProbability(int _BoxSize, int _MinDoubleYolks, double _ProbDoubleYolk) { double calculateProbabilityVal = 0; for (int i=0; i < _MinDoubleYolks; i++) { calculateProbabilityVal += pow(_ProbDoubleYolk, i) * pow(1 - _ProbDoubleYolk, _BoxSize - i) * combination(_BoxSize, i); } return 1- calculateProbabilityVal; } void runCode() { float ProbDoubleYolk = .01; long Simulations = 1000000000; int MaxBoxSize = 12; int MinDoubleYolks = 2; srand (time(NULL)); for (int BoxSize=1; BoxSize <= MaxBoxSize; BoxSize++) { long DoubleYolkBoxes = 0; for (int i = 0; i < Simulations; i++ ) { int CurrentDoubleYolkNum = 0; for (int egg = 1; egg <= BoxSize; egg++) { double r = ((double) rand() / (RAND_MAX)); if (r < ProbDoubleYolk) { CurrentDoubleYolkNum++; if (CurrentDoubleYolkNum >= MinDoubleYolks){ DoubleYolkBoxes++; break; } } } } double Prob = (double) DoubleYolkBoxes/ Simulations; cout << "Simulation: BoxSize = " << BoxSize << " and probability of having at least " << MinDoubleYolks << " double yolk eggs is " << setprecision(6) << Prob << '\n'; cout << "Theoretical: BoxSize = " << BoxSize << " and probability of having at least " << MinDoubleYolks << " double yolk eggs is " << setprecision(6) << calculateProbability(BoxSize, MinDoubleYolks, ProbDoubleYolk) << '\n'; cout << endl << endl; } } int main() { runCode(); return 0; } |

1 2 |
Simulation: BoxSize = 12 and probability of having at least 3 double yolk eggs is 0.00020417 Theoretical: BoxSize = 12 and probability of having at least 3 double yolk eggs is 0.000205616 |