For the current task, there is a software module in C# that allows obtaining test results and calculating probabilities in an iterative manner.
There is a game cycle (for calculations, we assume it to be infinite) in which there are two events.
The first event is the main one in the game cycle.
The second is additional; its occurrence depends on the required condition in the first event.
In the first event, a one-dimensional array of 20 elements is created.
int[] array = new int[20];
- We choose the number of elements to which values will be written. Each entry is the value of the coin's denomination.
From the first array, which determines the weight of the number of elements to be written.
int[] freq_element = new int[] { 170000, 300000, 285000, 178000, 59500, 4410, 2340, 720, 30 };
From the second array, which determines the number of elements to be written
int[] count_element = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
- Randomly select positions of elements in the array in the quantity obtained above.
If we randomly hit an already occupied position, we select a new position.
- Assign values to the selected elements.
From the first array, which determines the weight of the coin's denomination.
int[] freq_base = new int[] { 19000, 8000, 4000, 2500, 1000, 800, 350, 500, 350, 80, 20, 6 };
From the second array, which determines the denomination of the coin itself.
int[] value_base = new[] { 1, 2, 3, 4, 5, 10, 15, 10, 20, 50, 70, 100 };
- If the number of coins is 5 or more, this determines the beginning of the second event.
The second event.
For the remaining elements 20 - N, we create a loop for writing, where N is the number of coins in the first event.
Array elements that do not have a coin denomination (no record of the coin) by default have a value of 0.
- Sequentially for each element of the array that has a value of 0, we determine the condition for writing a new coin.
The probability of writing is determined by the weight from the array
int[] new_write = new int[] { 14000, 36606 };
where element 0 - no record; element 1 - there is a record.
- The condition for writing is set; there is a record.
From the first array, which determines the weight of the coin's denomination.
int[] freq_add = new int[] { 19000, 8000, 4000, 2500, 1000, 800, 350, 500, 350, 80, 20, 6 };
From the second array, which determines the denomination of the coin itself.
int[] value_base = new[] { 1, 2, 3, 4, 5, 10, 15, 10, 20, 50, 70, 100 };
What will be the average sum of values/denominations in the array under the condition of the second event occurring.
What will be the average sum of values/denominations in the array under the condition of the second event occurring and an additional condition:
- when the number of coins in the array is exactly 15, then they are multiplied by X.
------------------------------------------------------------------------------------------------------------------
my solution:
there are probabilities for the occurrence of the second event
p(N=5) = 0.00441
p(N=6) = 0.00234
p(N=7) = 0.00072
p(N=8) = 0.00003
The probability of adding a new coin
pHave = 36606 / (14000 + 36606) = 0.7234
The probability of not having a coin
pLost = 1 - 0.7234 = 0.2766
The expected average value of the coin's denomination is
E = (1*19000 + 2 * 8000 + 3 * 4000....70 * 20 + 100 * 6) / (19000 + 8000 .... + 20 + 6) = 2.547
The average value of coins in the first event
t_one = 5 * p(N=5) + 6 * p(N=6) + 7 * p(N=7) + 8 * p(N=8);
The average value of coins in the second event
t_two = (p(N=5) * 15 * pHave) + (p(N=6) * 14 * pHave) + (p(N=7) * 13 * pHave) + (p(N=8) * 12 * pHave);
The average total sum of coin denominations
S = (t_one + t_two) * E;
The probabilistic calculation completely matched the iterative result in the active model at 1,000,000,000 cycles.
Now an additional condition appears in the task (when the number of coins is 15, then all values/denominations are multiplied by X)
we find the probability of 15 records occurring when the first event has 5 - 8 records
p15_5 = BinomialCoefficient(15, 10) * Math.Pow(pHave, 10) * Math.Pow(pLost, 5) * p(N=5);
p15_6 = BinomialCoefficient(15, 9) * Math.Pow(pHave, 9) * Math.Pow(pLost, 5) * p(N=6);
p15_7 = BinomialCoefficient(15, 8) * Math.Pow(pHave, 8) * Math.Pow(pLost, 5) * p(N=7);
p15_8 = BinomialCoefficient(15, 7) * Math.Pow(pHave, 7) * Math.Pow(pLost, 5) * p(N=8);
The total probability of 15 records occurring is (it is almost equal to iterative measurements)
p15_total = p15_5 + p15_6 + p15_7 + p15_8;
The absolute probability in the second event (the probability within the bonus cycle)
p15_absol = p15_total / (p(N=5) + p(N=6) + p(N=7) + p(N=8));
The average sum of denominations with 15 coins
M = 15; // number of records
X = 1; // multiplier
S15 = p15_total * M * X * E
The average total sum of values/denominations
S_total = S15 + (1 - p15_absol) * S;
In my view, S_total == S
but the result does not match by about 0.5 - 1.0 percent.
it needs to be clarified what the reason is.