Created
October 3, 2009 08:01
-
-
Save jeek/200474 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $total=0; | |
| for ($trial=1;$trial<=10000;$trial++) { | |
| $answer=1+int(rand()*52); | |
| print "Trial: $trial\tAnswer: $answer\tGuesses: "; | |
| $guess=-1; $tries=0; | |
| while ($guess != $answer) { | |
| $guess=1+int(rand()*52); | |
| $tries++; | |
| } | |
| print "$tries\n"; | |
| $total+=$tries; | |
| } | |
| print "".($total/10000)."\n"; |
This file contains hidden or 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
| # how many tries until you are 50% likely to have found the card | |
| while ($total<.5) { | |
| $total+=1.0/52.0 * (51.0/52.0)**$i++; | |
| } | |
| print "$i $total\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment