I'm trying to do a script to perform all the permutations/combinations for 6 numbers from 0 to 45, without repetitions, but it's not working because some numbers repets in the same line.
What i'm doing wrong?
CODE:
for($a=0; $a<45-5; $a++)
for($b=$a+1; $b<45-4; $b++)
for($c=$b+1; $c<45-3; $c++)
for($d=$c+1; $d<45-2; $d++)
for($e=$d+1; $d<45-1; $d++)
for($f=$e+1; $d<45; $d++)
echo "$a $b $c $d $e $f \n";
I'm testing another code but I receive this error:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes)
<?php
function permutations($arr,$n)
{
$res = array();
foreach ($arr as $w)
{
if ($n==1) $res[] = $w;
else
{
$perms = permutations($arr,$n-1);
foreach ($perms as $p)
{
$res[] = $w." ".$p."<p>";
}
}
}
return $res;
}
$words = array('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45');
$pe = permutations($words,6);
print_r($pe);
?>
What I'm doing wrong?
Thank you