Skip to content

Instantly share code, notes, and snippets.

@jeek
Created October 3, 2009 08:01
Show Gist options
  • Save jeek/200474 to your computer and use it in GitHub Desktop.
Save jeek/200474 to your computer and use it in GitHub Desktop.
$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";
# 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