PHP is a combination of 1 to 9 numbers equals 20 method, PHP permutation combined _php Tutorial

Source: Internet
Author: User

PHP is a combination of 1 to 9 numbers equal to 20 of the method, the PHP permutation


This example describes how PHP can add 1 to 9 numbers equal to 20 by arranging combinations. Share to everyone for your reference. The implementation method is as follows:

<?phpset_time_limit (0);/* Function Description: Huoqu_zhuhe ($eq, $jiashu, $isone =0) parameter description: $eq---sum of several numbers; $jiashu-------addend array: $ Jiashu=array (1,2,3,4,5,6,7,8,9), which can be used addend; $isone---whether to use a different addend each time, uniqueness, 1 is 0 no, the default 1 return type: array, number with + concatenated string: [0] = = 3+8+9 [1] = > 4+7+9 Test Results: 1: For the addend array is small, the speed can, too big, some slow; 2: Each time you can use a different addend, the process will be slow to use the method is: to generate all possible permutations, filtering on the arrangement of duplicate, get the combination */function huoqu_ Zhuhe ($eq, $jiashu, $isone =1) {if (empty ($jiashu) | |! Is_array ($jiashu)) {echo ' ERROR: Addend must array '; return false;} $feishu =0;for ($i =0; $i
 
  $EQ) Break;else if (($nowhe + $jiashu [$j]) = = $eq) {$savearr []= $savestr;} else{$newarr [$k]= $savestr; $k + +;}} End for ($j =0; $j
  
   
  
 

The results of the operation are as follows:

Array (  [0] = 3+8+9  [1] = 4+7+9  [2] = 5+6+9  [3] = = 5+7+8  [4] = = 1+2+8+9  [5] => ; 1+3+7+9  [6] = 1+4+6+9  [7] = 1+4+7+8  [8] = = 1+5+6+8  [9] = = 2+3+6+9  [ten] = 2+3+7+8< C11/>[11] = 2+4+5+9  [[] = 2+4+6+8  [] = 2+5+6+7  [+] = 3+4+5+8  [] = 3+4+6+7< C16/>[16] = 1+2+3+5+9  [+] = 1+2+3+6+8  [+] = 1+2+4+5+8  [+] = 1+2+4+6+7  [+] = 1+3+4+5+7  [+] = 2+3+4+5+6)

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1042687.html www.bkjia.com true http://www.bkjia.com/PHPjc/1042687.html techarticle PHP is a combination of 1 to 9 of the number is equal to 20 of the method, the PHP permutation of the example of this article describes PHP through the permutation of the combination of 1 to 9 numbers equals 20 of the method. Share to the big ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.