6
I’m making a calculator to estimate the probability of lottery hits.
I’m using this formula:
Being:
- to is the number of tens of the steering wheel (at Mega-sena, a = 60)
- b is the number of dozens drawn (in Mega-Sena, b = 6)
- k is the number of tens per steering wheel (on the Mega-sena if our steering wheel has 6 dozens, k = 6)
- i total numbers that must be hit to win such a prize (for sena, i = 6, for the corner, i = 5 and for the court, i = 4)
Explained, let’s go to PHP. I made the following code:
<?php
$a = $_POST['a'];
$b = $_POST['b'];
$k = $_POST['k'];
$i = $_POST['i'];
// Realizando as subtrações
$c1 = $a - $k;
$c2 = $b - $i;
// Calculo para Ca-k,b-i
$calculo_1 = gmp_fact($c1) / (gmp_fact($c2) * gmp_fact(($c1 - $c2)));
// Calculo para Ck,i
$calculo_2 = gmp_fact($k) / (gmp_fact($i) * gmp_fact(($k - $i)));
// Calculo para Ca,b
$calculo_3 = gmp_fact($a) / (gmp_fact($k) * gmp_fact(($a - $k)));
// Multiplicação de Ca-k,b-i com Ck,i
$calculo_4 = $calculo_1 * $calculo_2;
// Simplificando
$calculo_final_cima = $calculo_4 / $calculo_4;
$calculo_final_baixo = $calculo_3 / $calculo_4;
echo "Probabilidade de acerto " . $calculo_final_cima . " em " . $calculo_final_baixo;
?>
The math checks out when $k
receives the standard values of the lotteries (Mega-sena: 6, Lotofácil: 15, Quina: 5 [...]), however, if assigned $k = 7
, getting:
// Exemplo da Mega Sena
$a = 60; // Números no total
$b = 6; // Dezenas que serão sorteadas
$k = 7; // Irei apostar com 7 números
$i = 6; // Acertos pretendidos
The expected result would be (according to the CEF): 1 in 7.151,980.
But I’m taking it back: 1 in 55,172,417.
Where I’m going wrong in the process?
I decided to change
$calculo_3 = gmp_fact($a) / (gmp_fact($k) * gmp_fact(($a - $k)));
for$calculo_3 = gmp_fact($a) / (gmp_fact($b) * gmp_fact(($a - $b)));
.– jsnow
Put as an answer.
– Juven_v