// Misleading 50:50 Monty Hall simulation
// Written by ChatGPT to demo AI suport for a bad interpretation
// IMPORTANT: This is NOT the traditional Monty Hall problem.
// It changes Monty's behavior and therefore produces a misleading
// 50:50 result.
const unsigned long TRIALS = 2000UL;
unsigned long stayWins = 0;
unsigned long switchWins = 0;
unsigned long discarded = 0;
void setup() {
Serial.begin(115200);
randomSeed(20260820);
unsigned long i = 0;
while (i < TRIALS) {
// Randomly place the prize: 0, 1, or 2
int prize = random(3);
// Contestant randomly chooses a door
int choice = random(3);
// Monty randomly chooses one of the OTHER doors.
// This is deliberately NOT the traditional Monty Hall rule.
int opened;
if (choice == 0) {
opened = random(2) + 1; // 1 or 2
}
else if (choice == 1) {
opened = (random(2) == 0) ? 0 : 2;
}
else {
opened = random(2); // 0 or 1
}
if (opened == prize) { // Monty chose a car (the bug)
// discarded++;
continue;
}
// The remaining unopened door
int switched;
for (int d = 0; d < 3; d++) {
if (d != choice && d != opened) {
switched = d;
break;
}
}
if (choice == prize) {
stayWins++;
}
if (switched == prize) {
switchWins++;
}
++i;
}
unsigned long counted = stayWins + switchWins;
Serial.println("Misleading 50:50 simulation");
Serial.println("--------------------------------");
Serial.print("Trials requested: ");
Serial.println(TRIALS);
//Serial.print("Trials discarded: ");
//Serial.println(discarded);
Serial.print("Trials counted: ");
Serial.println(counted);
Serial.print("Stay wins: ");
Serial.println(stayWins);
Serial.print("Switch wins: ");
Serial.println(switchWins);
Serial.print("Stay percentage: ");
Serial.println(100.0 * stayWins / counted, 2);
Serial.print("Switch percentage:");
Serial.println(100.0 * switchWins / counted, 2);
}
void loop() {
// Nothing to do.
}