Page 3 of 3
Posted: Thu Oct 19, 2006 1:54 pm
by volka
Ah yes. This method is much more suitable for small probabilites.
And it doesn't need bcmath (the main reason why my naive attempt is so slow)
Posted: Thu Oct 19, 2006 2:29 pm
by bokehman
volka wrote:Ah yes. This method is much more suitable for small probabilites.
And it doesn't need bcmath (the main reason why my naive attempt is so slow)
Well thanks for the input anyway. I think my biggest problem is I don't know maths very well so when someone posted a formula
49!/6! I didn't understand what it meant. Once I realised what that (and a few other things) meant all the pieces started to fall into place. I changed the code a little bit now. I added the possibility to work out probabilities for minor wins too and another function that works out the bonus ball.
Code: Select all
function Probability($N, $m, $n = null)
{
if(is_null($n)) return 1/ComputeOdds($N, $m);
if($n>$m||$m>$N) return 0;
return 1/(ComputeOdds($N, $m)/(ComputeOdds($m, $n)*ComputeOdds($N-$m, $m-$n)));
}
function ComputeOdds($d, $n)
{
if($d<$n||$n<1) return 0;
$r = 1;
while($n&&$r*=$d--/$n--);
return $r;
}
function NumPlays($prob, $percent)
{
if($prob == 1) return 1;
return intval(log(1-($percent/100))/log(1-$prob)+1);
}
echo '<p>Number of plays before reaching 50% probability of a minor win (3 balls): '.
number_format(NumPlays(Probability(49, 6, 3), 50));