本文介绍了如何降低回路速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临一个大问题。我需要生成确切的7号码组合,我写了一个代码,通过使用7 forloops,它也工作正常与少数。请检查附件,所以你会非常清楚我实际需要什么。
请提供PHP结果。

 <?php 
//我需要这个注解的组合数字
// 1,7,13,19,25,31,2,8,14,20,26,32,3,9,15,
// 21,27,33,4 ,10,16,22,28,34,5,11,17,23,29,
// 35,6,12,18,24,30,36
$ string = array(1 ,7,13,19,25,31,2,8,14,20,26,32,3,9,15,21,27,33,4,10,16,22,28,34);
$ len = count($ string);
$ c = 0;
ob_start(); ($ f = $ e + 1; $ f <$ len - 5)
$($ e $ 0; $ e <$ len-6; $ e ++)
{
($ $ = $ f + 1; $ g <$ len-4; $ g ++)
{


($ i = $ h + 1; $ i <$ len-2; $ i ++)$ b $(g + 1; $ h <$ len-3; $ h ++)
{
对于($ k = $ j + 1; $ k< $(b







$ ; $ len; $ k ++)
{
$ c ++;
$ output [] = $ string [$ e]。 ,。
$ string [$ f]。 ,。
$ string [$ g]。 ,。
$ string [$ h]。 ,。
$ string [$ i]。 ,。
$ string [$ j]。 ,。
$ string [$ k];
ob_flush();
}
ob_flush();
}
ob_flush();
}
ob_flush();
}
ob_flush();
}
ob_flush();
}
ob_flush();
}
echo count($ output);
?>

我需要输出和我下面提到的一样。
输出:

 传递数字$ string = array(1,7,13,19,25,31,2 ,8,14),并且输出低于
计数的组合= 36
阵列

[0] => 1,7,13,19,25, 31,2
[1] => 1,7,13,19,25,31,8
[2] => 1,7,13,19,25,31,14
[3] => 1,7,13,19,25,2,8
[4] => 1,7,13,19,25,2,14
[ 5] => 1,7,13,19,25,8,14
[6] => 1,7,13,19,31,2,8
[7] => ; 1,7,13,19,31,2,14
[8] => 1,7,13,19,31,8,14
[9] => 1,7 ,13,19,2,8,14
[10] => 1,7,13,25,31,2,8
[11] => 1,7,13,25 ,31,2,14
[12] => 1,7,13,25,31,8,14
[13] => 1,7,13,25,2,8 ,14
[14] => 1,7,13,31,2,8,14
[15] => 1,7,19,25,31,2,8
[16] => 1,7,19,25,31,2,14
[17] => 1,7,19,25,31,8,14
[18 ] => 1,7,19,25,2,8,14
[19] => 1,7,19,31,2,8,14
[20] => 1,7,25,31,2,8,14
[21] => 1,13,19,25,31,2,8
[22] => 1,13,19,25,31,2,14
[23] => 1,13,19,25,31,8,14
[24] => 1,13,19,25,2,8,14
[25] => 1,13,19,31,2,8,14
[26] => 1,13,25,31,2,8,14
[27] => 1,19,25,31,2,8,14
[28] => 7,13,19,25,31,2,8
[29] => 7,13,19,25,31,2,14
[30] => 7,13,19,25,31,8,14
[31] => 7,13,19,25,2,8,14
[32] => 7,13,19,31,2,8,14
[33] => 7,13,25,31,2,8,14
[34] => 7,19,25,31,2,8,14
[35] => 13,19,25,31,2,8,14


解决方案

 函数factorial($ factVal){
$ factorial = 1;
while($ factVal> 1){
$ factorial * = $ factVal--;
}
return $ factorial;


函数permutations($ numObjs,$ numInSet){
return round(factorial($ numObjs)/ factorial($ numObjs - $ numInSet));


函数组合($ numObjs,$ numInSet){
return round(factorial($ numObjs)/ factorial($ numObjs - $ numInSet))/ factorial($ numInSet );
}


$ string = array(1,7,13,19,25,31,2,8,14,20,26,32,3,9, 15,21,27,33,4,10,16,22,28,34);
echo'Number of Combinations ='.combinations(count($ string),7)。'< br />';
echo'Number of Permutations ='.permutations(count($ string),7)。'< br />';


i'm facing a big issue. i need to generate exact 7 number combinations and i written a code for that by using 7 forloops and also it is working fine with very less numbers.Please check the attachment so you will be very clear what i need actually. Please provide PHP result.

<?php
// I need the combinations for this commented numbers   
// 1, 7, 13, 19, 25, 31, 2, 8, 14, 20, 26, 32, 3, 9, 15, 
// 21, 27, 33, 4, 10, 16, 22, 28, 34, 5, 11, 17, 23, 29,
// 35, 6, 12, 18, 24, 30, 36
$string=array(1,7,13,19,25,31,2,8,14,20,26,32,3,9,15,21,27,33,4,10,16,22,28,34);
$len=count($string);
$c=0;
ob_start();
for ($e = 0; $e < $len - 6; $e++)
{
   for ($f = $e+1; $f < $len - 5; $f++)
   {
       for ($g = $f+1; $g < $len - 4; $g++)
       {
           for ($h = $g+1; $h < $len - 3; $h++)
           { 
               for ($i = $h+1; $i < $len - 2; $i++)
               {
                   for ($j = $i + 1; $j < $len - 1; $j++)
                   {
                        for ($k = $j + 1; $k < $len; $k++)
                        {
                             $c++;
                             $output[] = $string[$e] . "," . 
                                         $string[$f] . "," . 
                                         $string[$g] . "," .  
                                         $string[$h] . "," . 
                                         $string[$i] . "," . 
                                         $string[$j] . "," . 
                                         $string[$k];
                             ob_flush();
                        }
                        ob_flush();
                   }
                   ob_flush();
               }
               ob_flush();
           }
           ob_flush();
   }
   ob_flush();
}
ob_flush();
}
echo count($output);
?>

And I need the output same like i mentioned below. Output:

passed numbers $string=array(1, 7, 13, 19, 25, 31, 2, 8, 14) and the out put is below
count of combinations = 36
Array
(
    [0] => 1,7,13,19,25,31,2
    [1] => 1,7,13,19,25,31,8
    [2] => 1,7,13,19,25,31,14
    [3] => 1,7,13,19,25,2,8
    [4] => 1,7,13,19,25,2,14
    [5] => 1,7,13,19,25,8,14
    [6] => 1,7,13,19,31,2,8
    [7] => 1,7,13,19,31,2,14
    [8] => 1,7,13,19,31,8,14
    [9] => 1,7,13,19,2,8,14
    [10] => 1,7,13,25,31,2,8
    [11] => 1,7,13,25,31,2,14
    [12] => 1,7,13,25,31,8,14
    [13] => 1,7,13,25,2,8,14
    [14] => 1,7,13,31,2,8,14
    [15] => 1,7,19,25,31,2,8
    [16] => 1,7,19,25,31,2,14
    [17] => 1,7,19,25,31,8,14
    [18] => 1,7,19,25,2,8,14
    [19] => 1,7,19,31,2,8,14
    [20] => 1,7,25,31,2,8,14
    [21] => 1,13,19,25,31,2,8
    [22] => 1,13,19,25,31,2,14
    [23] => 1,13,19,25,31,8,14
    [24] => 1,13,19,25,2,8,14
    [25] => 1,13,19,31,2,8,14
    [26] => 1,13,25,31,2,8,14
    [27] => 1,19,25,31,2,8,14
    [28] => 7,13,19,25,31,2,8
    [29] => 7,13,19,25,31,2,14
    [30] => 7,13,19,25,31,8,14
    [31] => 7,13,19,25,2,8,14
    [32] => 7,13,19,31,2,8,14
    [33] => 7,13,25,31,2,8,14
    [34] => 7,19,25,31,2,8,14
    [35] => 13,19,25,31,2,8,14
)
解决方案
function factorial($factVal) {
    $factorial = 1;
    while ($factVal > 1) {
        $factorial *= $factVal--;
    }
    return $factorial ;
}

function permutations($numObjs,$numInSet) {
    return round(factorial($numObjs) / factorial($numObjs - $numInSet));
}

function combinations($numObjs,$numInSet) {
    return round(factorial($numObjs) / factorial($numObjs - $numInSet)) / factorial($numInSet);
}


$string=array(1,7,13,19,25,31,2,8,14,20,26,32,3,9,15,21,27,33,4,10,16,22,28,34); 
echo 'Number of Combinations = '.combinations(count($string),7).'<br />';
echo 'Number of Permutations = '.permutations(count($string),7).'<br />';

这篇关于如何降低回路速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 20:56