"Goat", 2=>"Goat", 3=>"Car"); shuffle($doors); $our_choice = array_rand($doors); $our_door = $doors[$our_choice]; unset($doors[$our_choice]); if (reset($doors) == "Goat") { // first door in the array contains a goat, // eliminate it from the list of choices // get the current key $cur_key = key($doors); unset($doors[$cur_key]); } else { next($doors); $cur_key = key($doors); unset($doors[$cur_key]); } if ($DoSwitch == "Yes") { if (reset($doors) == "Car") { return "Win"; } else { return "Lose"; } } else { if ($our_door == "Car") { return "Win"; } else { return "Lose"; } } } if (isset($_POST["DoSwitch"])) { $wins = 0; $losses = 0; for ($i = 0; $i < $_POST["Iterations"]; ++$i) { $result = MontyHall($_POST["DoSwitch"]); if ($result == "Win") { ++$wins; } else { ++$losses; } } print "

The Amazing Monty Hall Empirical Proof Device

"; print "

Number of iterations: {$_POST["Iterations"]}

"; print "

Contestant switches: {$_POST["DoSwitch"]}

"; print "

Number of wins: $wins

"; print "

Number of losses: $losses

"; } ?>

Number of iterations:

Should the contestant switch?