/>
Код: Выделить всё
public static double MontyHall(int numTests) {
int passedTests = 0;
for(int i = 0; i < numTests; ++i) {
List puertas = new ArrayList(Arrays.asList(0,0,0)); //0wrong door, 1right door, -1opened door
SecureRandom random = new SecureRandom();
int rightDoor = random.nextInt(3);
puertas.set(rightDoor, 1);
int choice = random.nextInt(3);
if(rightDoor == choice) {
int aux = random.nextInt(2);
for(int k = 0; k < puertas.size(); ++k) {
if(k != rightDoor && aux == 0) {
puertas.set(k, -1);
}
else if(k != rightDoor) --aux;
}
}
else {
for(int j = 0; j < puertas.size(); ++j) {
if(j != rightDoor && j != choice) puertas.set(j, -1);
}
}
for(int l = 0; l < puertas.size(); ++l) {
if(l != choice && puertas.get(l) != -1) choice = l;
}
if(puertas.get(choice) == 1) ++ passedTests;
}
return (double) passedTests /numTests;
}
Код: Выделить всё
0.61116
0.61065
0.61111
Подробнее здесь: https://stackoverflow.com/questions/792 ... me-of-0-61
Мобильная версия