Count 24 games Everyone has played, then how to use the program to calculate the 4 number of random combinations of the result is 24? For example, 5,5,5,1 these four numbers, how to get a result of 24? Here is a very powerful program that can list all the combinations that meet the criteria.
"; Makevalue ($values); Print_r ($list), function Makevalue ($values, $set =array ()) {$words = array ("+", "-", "*", "/"), if (sizeof ($values) ==1) {$s Et[] = Array_shift ($values); Return makespecial ($set); The foreach ($values as $key = = $value) {$tmpValues = $values; unset ($tmpValues [$key]); foreach ($words as $word) {Makevalu E ($tmpValues, Array_merge ($set, Array ($value, $word))); }}} function Makespecial ($set) {$size = sizeof ($set); if ($size <=3 | |!in_array ("/", $set) &&!in_array ("*", $ Set) {return Makeresult ($set);} For ($len =3, $len < $size-1; $len +=2) {for ($start =0; $start < $size-1; $start +=2) {if (!) ( $set [$start -1]== "*" | | $set [$start -1]== "/" | | $set [$start + $len]== "*" | | $set [$start + $len]== "/")) continue; $subSet = Array_slice ($set, $start, $len); if (!in_array ("+", $subSet) &&!in_array ("-", $subSet)) continue; $tmpSet = $set; Array_splice ($tmpSet, $start, $len-1); $tmpSet [$start] = "(". Implode ("", $subSet). ")"; Makespecial ($tmpSet); }}}function Makeresult ($sET) {global $result, $list; $str = Implode ("", $set); @eval ("\ $num = $str;"); if ($num = = $result &&!in_array ($str, $list)) $list [] = $STR; }?>
The result of the program operation is:
Array ( [0] = (5-1/5) [1] = 5* (5-1/5))