Könnte mir jemand erklären, weshalb der Spieler häufiger die Ziege zieht, wenn er nach der Frage des Quizmasters nicht die Tür wechselt?
Java:
import java.util.Random;
public class Ziege {
public static void main(String[] args) {
int switchDoor = 0;
int noSwitchDoor = 0;
for (int i = 0; i < 100_000; i++) {
switchDoor += simulate(true);
noSwitchDoor += simulate(false);
}
System.out.printf("Switch door: %f%%%n", switchDoor / 1000.);
System.out.printf("No switch door: %f%%%n", noSwitchDoor / 1000.);
}
private static int simulate(boolean switchDoor) {
Random random = new Random();
final int ziegeAt = random.nextInt(3);
final int playerChoose1 = random.nextInt(3);
if (ziegeAt == playerChoose1) {
// The player has chosen the door with the goat behind it.
return 0;
}
int playerChoose2;
do {
playerChoose2 = random.nextInt(3);
} while (playerChoose2 == playerChoose1);
// Ask the player to switch the chosen door:
if (switchDoor) {
playerChoose2 = playerChoose1 ^ playerChoose2 ^ 3;
}
if (playerChoose2 == ziegeAt) {
// The player has chosen the door with the goat behind it.
return 1;
}
// The player has chosen the door with the car behind it.
return 2;
}
}