-1
So, I’m new to php and I couldn’t, after many attempts and in different ways, create something like.
I enter a value for the amount of numbers I will create in each combination in a given set of numbers.
I want for example, combinations with 5 numbers of this set below; Set [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40]
... I really need a light here.... I’ve already lost more than 2 days creating shapes and nothing. I tried to do with recursive calls but from 3 numbers generates error....
<?php
$qntdElementos = 5;
$tipoConjunto = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40];
$max = max($tipoConjunto);
// var_dump($max);
$maxPrimeiraPosicao = max(array_keys($tipoConjunto))-($qntdElementos-1);
$limiteMaxTipoConjunto = max(array_keys($tipoConjunto));
$limiteMinTipoConjunto = min(array_keys($tipoConjunto));
$posicaoInicial = $qntdElementos-1;
$novaPosicaoMudanca = $posicaoInicial-1;
$arrayMutavel=[];
$combinacoes=[];
$strMutavel = "";
for ($a=$limiteMinTipoConjunto;$a<=$posicaoInicial;$a++){
$strMutavel.="$a ";
$arrayPosicoes[]=$a;
}
$maxPosicoes = max(array_keys($arrayPosicoes));
$arrayMutavel = explode(" ",trim($strMutavel));
var_dump($arrayMutavel, $maxPosicoes);
$c=-1;
$cp=$maxPosicoes+1;
do{
$cp--;
var_dump($cp);
$vp = -1; //Valida a posição inicial
$mp = $arrayPosicoes[$cp]; // Modificador de posição
do {
$c++;
$vp++;
var_dump($mp, $arrayMutavel);
$vp>0?$pos = ($posicaoInicial + ($vp - 1)):$pos = $mp;
$strMutavel = substr_replace($strMutavel,($posicaoInicial+$vp),strpos($strMutavel,"$pos"));
$arrayMutavel = explode(" ",trim($strMutavel));
for ($a = 0; $a <= $qntdElementos - 1; $a++) {
if (isset($tipoConjunto[$arrayMutavel[$a]])) {
$combinacoes[$c][] = $tipoConjunto[$arrayMutavel[$a]];
}elseif (count($combinacoes[$c])<$qntdElementos){
unset($combinacoes[$c]);
}
}
}while($c<$limiteMaxTipoConjunto-1);
echo "Saindo do primeiro loop = $strMutavel";
$arrayMutavel = explode(" ",trim($strMutavel));
$tmpArrayMutavel = $arrayMutavel[$cp-1];
$tmpStrMutavel = $pos+1;
$strMutavel = substr_replace($strMutavel,$tmpArrayMutavel+1,strpos($strMutavel,"$tmpArrayMutavel"));
var_dump($strMutavel, $tmpArrayMutavel);
}
while($cp>0);
return $this->combinacoes = $combinacoes;
The return has been;
C:\xampp\htdocs\lotofacil\source\estrategias\estrategias.php:88:
array (size=5)
0 => string '0' (length=1)
1 => string '1' (length=1)
2 => string '2' (length=1)
3 => string '3' (length=1)
4 => string '4' (length=1)
C:\xampp\htdocs\lotofacil\source\estrategias\estrategias.php:88:int 4
C:\xampp\htdocs\lotofacil\source\estrategias\estrategias.php:88:
array (size=5)
0 => string '0' (length=1)
1 => string '1' (length=1)
2 => string '2' (length=1)
3 => string '3' (length=1)
4 => string '5' (length=1)
Until the error occurs;
C:\xampp\htdocs\lotofacil\source\estrategias\estrategias.php:88:
array (size=5)
0 => string '0' (length=1)
1 => string '1' (length=1)
2 => string '2' (length=1)
3 => string '3' (length=1)
4 => string '22' (length=2)
( ! ) Notice: Undefined offset: 1 in C:\xampp\htdocs\lotofacil\source\estrategias\estrategias.php on line 93
Call Stack
# Time Memory Function Location
1 0.0001 418400 {main}( ) ...\estrategias.php:0
2 1.2059 8063776 source\estrategias\estrategias->geraCombinacoes( ) ...\estrategias.php:18
The idea is not to order Felipe but to create the combinations but, still, grateful.
– adailtondossantos