Created
October 28, 2011 14:17
-
-
Save PEM-FR/1322378 to your computer and use it in GitHub Desktop.
biasedMonty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$results = array(); | |
$wrongs = array(); | |
for ($i = 0; $i < 100000; $i++) { | |
$result[$i] = mt_rand(1,3); | |
$wrongs[$i][0] = ($result[$i] - 1 == 0) ? 3 : $result[$i] - 1; | |
$wrongs[$i][1] = 6 - $result[$i] - $wrongs[$i][0]; | |
} | |
$JackResults = 0; | |
$BobResults = 0; | |
for ($i = 0; $i < 100000; $i++){ | |
$jackChoice = $bobChoice = mt_rand(1,3); | |
// jack never switches, let's see if he was right ! | |
if($jackChoice == $result[$i]) ++$JackResults; | |
// since the dealer will always show a wrong, and bob will always switch, we can assume that if bob did not win first, | |
// he will when he switches | |
// bob always switches, let's see if he was right ! | |
if($bobChoice !== $result[$i]) ++$BobResults; | |
} | |
echo "<br/>Jack never switches, nb good answers : " . $JackResults; | |
echo "<br/>Bob always switches, nb good answers : " . $BobResults; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment