Php uses the permutation and combination method to add numbers from 1 to 9 equal to 20. Php uses the permutation and combination method to add numbers from 1 to 9 equal to 20. the example in this article describes how php uses the arrangement and combination method to add numbers from 1 to 9 equal to 20. Share with big php the method of adding numbers from 1 to 9 by means of permutation and combination is equal to 20.
The example in this article describes how php adds 20 numbers from 1 to 9 by means of permutation and combination. Share it with you for your reference. The specific implementation method is as follows:
<? Phpset_time_limit (0);/* function description: huoqu_zhuhe ($ eq, $ jiashu, $ isone = 0) parameter description: $ eq --- sum of several counts; $ jiashu ------- addend array: $ jiashu = array (, 9), addend that can be used; $ isone --- whether to use different addend each time, uniqueness, the value 1 is 0. the default value is 1. return type: Array. The number is A +-connected string: [0] => 3 + 8 + 9 [1] => 4 + 7 + 9 test results: 1: For a small number of addition arrays, the speed is acceptable. if it is too large, A little slow; 2: You can use different numbers each time. the method to slow down processing is to generate all possible arrays and filter duplicate sorting, get the combination */function huoqu_zhuhe ($ eq, $ jiashu, $ isone = 1) {if (empty ($ jiashu) |! Is_array ($ jiashu) {echo 'Error: an array of numbers required '; 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 running result is 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 [10] => 2+3+7+8 [11] => 2+4+5+9 [12] => 2+4+6+8 [13] => 2+5+6+7 [14] => 3+4+5+8 [15] => 3+4+6+7 [16] => 1+2+3+5+9 [17] => 1+2+3+6+8 [18] => 1+2+4+5+8 [19] => 1+2+4+6+7 [20] => 1+3+4+5+7 [21] => 2+3+4+5+6)
I hope this article will help you with php programming.
Examples in this article describes how to add numbers from 1 to 9 by means of arrangement and combination in php. Share with me...