>>11825411Here's some code that should explain a bit for you.
[code:lit]
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <vector>
enum metalballs{
silver=0,
gold=1
};
int main(){
srand(time(0));
std::vector<std::vector<metalballs>> boxes = {{silver, silver}, {silver, gold}, {gold, gold}};
unsigned int double_gold = 0;
unsigned int single_gold = 0;
unsigned int gold_first = 0;
for(int i=0;i<100000;++i){
unsigned int box = rand() % 3;
unsigned int ball = rand() % 2;
if (boxes[box][ball] == gold && boxes[box][!ball] == gold){
double_gold += 1;
gold_first += 1;
}
else if (boxes[box][ball] == gold && boxes[box][!ball] == silver){
single_gold += 1;
gold_first += 1;
}
}
std::cout << "overall probability of the box situation:" << std::endl;
std::cout << "the number of double golds: " << double_gold << " - " << (double)double_gold/(double)gold_first << "%" << std::endl;
std::cout << "the number of gold then silver: " << single_gold << " - " << (double)single_gold/(double)gold_first << "%" << std::endl;
}
[/code:lit]