I'm not as eloquent as Robinson, so I'll just quote the book for his wonderful explanation.
One test that had caught even Frank, despite his vigilance, was the three-box game. Three boxes, all closed, one ten-dollar bill hidden in one of them; the experimenter knows which. Subject chooses one box, at that point left closed. Experimenter opens one of the other two boxes, always an empty one. Subject then offered a chance to either stick with his first choice, or switch to the other closed box. Which should he do?It boggles the mind, right? After having it explained I do have some grasp of why it happens that way, but I still felt the need to empirically test it. So I wrote a little PHP script that plays the three-box game with itself, and set it to run a hundred thousand times each way.
Frank had decided it didn't matter; fifty-fifty either way. He thought it through.
But each box at the start had a one-third chance of being the one. When subject chooses one, the other two have two-thirds chance of being right. After experimenter opens one of those boxes, always empty, those two boxes still have two-thirds of a chance, now concentrated in the remaining unchosen box, while the subject's original choice still had its original one-third chance. So one should always change one's choice!
And what do you know? This is one thought-puzzle that holds up to empirical testing!
Played 100000 games each:If you're so inclined, here's the PHP I used:
bet kept: 33268 wins
bet changed: 66738 wins
<?php
function boxgame ($change_bet) {
$boxes = array();
$bet = rand(1,3);
$coin = rand(1,3);
$boxes[1] = 'empty';
$boxes[2] = 'empty';
$boxes[3] = 'empty';
$boxes[$coin] = 'coin';
//echo "<div>Bet on $bet, coin is in $coin</div>";
//this is where the actual game is played
if ($change_bet == true) {
//echo "<div>changing bet</div>";
foreach ($boxes as $box => $content) {
if ($box == $bet) {
//echo "<div>can't remove $box, player has bet on it</div>";
}elseif ($content == 'coin') {
//echo "<div>can't remove $box, it has the coin in it</div>";
}else {
//echo "<div>removing box $box from the game</div>";
unset($boxes[$box]);
break;
}
}
//echo "<div>changing bet from $bet to ";
foreach ($boxes as $box => $content) {
if ($box != $bet) {
$bet = $box;
//echo "$bet</div>";
break;
}
}
}
if ($boxes[$bet] == 'coin') {
$result = 'win';
}else {
$result = 'lose';
}
return($result);
}
$iterations = 100000;
$results = array();
$results['keep bet'] = array();
$results['change bet'] = array();
for ($i = 1; $i <= $iterations; $i++) {
$results['keep bet'][boxgame(false)]++;
$results['change bet'][boxgame(true)]++;
}
echo "Played $iterations games each:<br>bet kept: ".$results['keep bet']['win']." wins<br>bet changed: ".$results['change bet']['win']." wins";
/*var_dump($results);/**/
?>
0 comments:
Post a Comment