Lot closure easy with error in PHP printing [closed]

closed. this question is out of scope and is not currently accepting answers.

want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 8 months ago .

improve this question

Guys, I need your help if possible... I created a game generation system in lotofácil, based on another system... Well my system is not very complex... user choose 5 tens / numbers to exclude from your games, and the generator generates 356 different combinations...

Until then all right, I managed to make the code that generates all possible combinations in the sequence of 20 numbers, making combinations of 15... and I show to the user 356 of the more than 15 thousand combinations...

My system compares the numbers with the last game, and tells you how many points and reais (R$) the user would have made with those games...

The problem is that in the other system, the combinations that are "generated" when you exclude the 5 numbers, always gives at least 1 result of 14 hits and not mine, because it makes the exclusion of 5 numbers that did not come out in the last contest...

//Primeiras Impressões do Sistema Excluindo as Dezenas: 02  03  05  08 09

1   4   4   6   7   10  11  12  13  14  15  16  18  22  23
1   4   4   6   7   10  11  12  13  14  15  18  19  20  21
1   4   4   6   7   10  11  12  13  14  16  18  19  22  24
1   4   4   6   7   10  11  12  13  14  17  18  19  23  24
1   4   4   6   7   10  11  12  13  15  16  17  18  22  23
1   4   4   6   7   10  11  12  13  15  16  18  20  21  22
1   4   4   6   7   10  11  12  13  15  16  20  21  22  23
1   4   4   6   7   10  11  12  13  15  17  18  20  21  24
1   4   4   6   7   10  11  12  13  16  17  20  22  23  24
1   4   4   6   7   10  11  12  13  16  18  21  22  23  24
1   4   4   6   7   10  11  12  14  15  16  17  19  20  23

These are the first 11, but you can already notice that they are very different from mine that are:

//Primeiras Impressões do Meu Sistema Excluindo as Dezenas: $exclusao=["02","03","05","08","09"];

Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 19 [14] => 20 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 19 [14] => 21 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 19 [14] => 22 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 19 [14] => 23 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 19 [14] => 24 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 19 [14] => 25 ) 
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 20 [14] => 21 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 20 [14] => 22 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 20 [14] => 23 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 20 [14] => 24 )
Array ( [0] => 01 [1] => 04 [2] => 06 [3] => 07 [4] => 10 [5] => 11 [6] => 12 [7] => 13 [8] => 14 [9] => 15 [10] => 16 [11] => 17 [12] => 18 [13] => 20 [14] => 25 )

My build code is this:

$dezenas =array_diff($numeros,$exclusao);
sort($dezenas);
function combinacoesDe($k, $xs){
    if ($k === 0)
        return array(array());
    if (count($xs) === 0)
        return array();
    $x = $xs[0];

    $xs1 = array_slice($xs,1,count($xs)-1);

    $res1 = combinacoesDe($k-1,$xs1);

    for ($i = 0; $i < count($res1); $i++) {
        array_splice($res1[$i], 0, 0, $x);
    }
    $res2 = combinacoesDe($k,$xs1);

    return array_merge($res1, $res2);
}
$resultado = combinacoesDe(15,$dezenas);

And the printing and comparison is this:

  <?php $numaposta=1;
		for($z =1  ; $z <= 356 ; $z++) {		
echo "<div class='mostra-aposta'>";
echo"<h4 style=''>Aposta $numaposta </h4>";
$numaposta=$numaposta+1;
for($x = 1 ; $x <= 25 ; $x++) { ?>
<span <?php if(in_array($x,$resultado[$z])!== FALSE){echo"class='ok'";}elseif(in_array($x,$exclusao)!== FALSE){echo"class='ok2'";}else{} ?>><?php echo"$x"; ?></span>
<?php
}
$quantos = array_intersect($dezenasr, $resultado[$z]);
$premio = count($quantos);
	if($premio===15){
	array_push($a15, $z);
}elseif($premio===14){
	array_push($a14, $z);
}elseif($premio===13){
	array_push($a13, $z);
}elseif($premio===12){
	array_push($a12, $z);
}elseif($premio===11){
	array_push($a11, $z);
}
echo "</div>";
}
$puxarht=ob_get_contents();
$htb64=base64_encode($puxarht);
ob_end_flush();
$n15=count($a15);
$n14=count($a14);
$n13=count($a13);
$n12=count($a12);
$n11=count($a11);
$premio15=$quinze -> valor_pago * $n15;
$premio14=$quatorze -> valor_pago * $n14;
$premio14=str_replace(".","",$premio14);
$premio13=$treze -> valor_pago * $n13;
$premio12=$doze -> valor_pago * $n12;
$premio11=$onze -> valor_pago * $n11;
$premiototal=$premio15+$premio14+$premio13+$premio12+$premio11;
$totaldeacertos=$n11+$n12+$n13+$n14+$n15;
?>

I've done the comparison and all the as sequences generated in their system are among my more than 15,000 combinations... the problem is that far apart from each other... I would appreciate it if you could help me with that, thank you!

Author: George Wurthmann, 2019-07-05

1 answers

I did something similar, I generate more combinations than necessary, in addition I continue to generate combinations if it does not hit 14 points, then I exclude from the array the combinations that give fewer points.

I'm copying the code here to vc...

public function apostasr5_pre(Request $request){

    $numeros = $request->input('param2');
    $concurso_id = $request->input('param3');
    $concurso = resultados::where('id',$concurso_id)->first();
    $concurso_valor = unserialize($concurso->valores);
   
    $id = $this->GERA_R5($numeros);
 
    $g = saved_games::where('id',$id)->first();
    $sequencias = unserialize($g->games);
  
    $acerta11=0; $acerta12=0;  $acerta13=0; $acerta14=0; $acerta15=0;
    foreach($sequencias as $jogos){
        $cont=0;
        
        foreach($jogos as $jogo){
            if(in_array($jogo, $concurso_valor)){ 
                $cont++; 
            
            }
           
        }//endforeach1    
       
            if($cont == 11){ $acerta11++; } 
            if($cont == 12){ $acerta12++; } 
            if($cont == 13){ $acerta13++; } 
            if($cont == 14){ $acerta14++; } 
            if($cont == 15){ $acerta15++; }
         
    }//endforeach2
    $arr=[];

    array_push($arr ,['11',$acerta11, ($acerta11 * $concurso->acertos11) ]);
    array_push($arr ,['12',$acerta12, ($acerta12 * $concurso->acertos12) ]);
    array_push($arr ,['13',$acerta13, ($acerta13 * $concurso->acertos13) ]);
    array_push($arr ,['14',$acerta14, ($acerta14 * $concurso->acertos14) ]);
    array_push($arr ,['15',$acerta15, ($acerta15 * $concurso->acertos15) ]);

    return view('resultados.conferencia')->with('dados',$arr);

}

public function GERA_R5($numeros){

    //saved_games::truncate();

    $id_game = 'Lotofácil-Erre-5';
    $date_show = '2020-04-02 00:00:00';
    
    $numeros_arr = array_map('intval',explode("-",$numeros));
    sort($numeros_arr);
   
    $resultados = resultados::orderby('concurso','desc')->take(370)->get();
    $data = $resultados[0]->data;
    $g = saved_games::where('sequence',serialize($numeros_arr))
                    ->where('id_game',$id_game)->where('created_at','>=',$data)
                    ->first();
     if(!$g){

        $g = new saved_games;
        $g->id_game = $id_game;
        $g->sequence = serialize($numeros_arr);
        $g->user_id = auth()->user()->id;
        $g->date_show = $date_show;
        
      
        $mestre= [];
        $out = [];

        foreach($resultados as $resultado){
        

        $acertos = 0;
        $out = [];
        $max = 14;
        $valor_resultado = unserialize($resultado->valores);
     
        $errei = 0;
        $errei = $this->conta($valor_resultado,$numeros_arr);

  

        if($errei == 0){ $max=14; }
        else { $max = 1; }    

            while($acertos < $max){
                $dezena = $this->gera_dezena_r5($numeros_arr);
                $acertos = $this->conta($valor_resultado, $dezena);
            }

        
            array_push($mestre,$dezena); 
        } //for mestre

        $mestre = array_unique($mestre, SORT_REGULAR);
        array_splice($mestre, 356);

        $g->games = serialize($mestre);
        $g->save();

           
     }

     return $g->id;   

}

public function gera_dezena_r5($numeros){
            $in = $numeros;
            $out = [];
                for ($i=0; $i < 15; $i++) {
                    do {
                        $rand = rand(1, 25);
                    } while(in_array($rand, $in));
                    array_push($in, $rand);
                    array_push($out, $rand);
                } //for completa
            sort($out);
return  $out;
}




public function conta($r,$d){
    $cont=0;
    foreach($r as $valor){
      if(in_array($valor,$d)){
          $cont +=1;
      }
    }
    return $cont;
}
 -1
Author: Thiago Marcato, 2020-06-18 17:37:03