fork(1) download
  1. <?php
  2. header('Content-type: text/html; charset=utf-8');
  3. $digits = array(11, 10, 16, 7, 14, 17, 12, 13);
  4. $size = count($digits) - 1;
  5. $sum = array_sum($digits);
  6. $newDigits = array();
  7. for ($i = 0; $i <= $size; $i++) {
  8. perm($i, $digits, $newDigits);
  9. }
  10. function perm($k, &$array, &$newArray)
  11. {
  12. for ($q = 0; $q+$k < count($array); $q++) {
  13. $newArray[$k + $q] = $array[$k + $q];
  14. if ($k < (count($array) - 1)) {
  15. perm($k + $q + 1, $array, $newArray);
  16. }
  17. checkArray($newArray, $array);
  18. unset($newArray[$k + $q]);
  19. }
  20. }
  21. function checkArray (&$array, &$arrayOld)
  22. {
  23. if (array_sum($array) * 2 == array_sum($arrayOld)) {
  24. $newArray = array();
  25. foreach ($arrayOld as $index => $element) {
  26. if (!(isset($array[$index]))) {
  27. $newArray[] = $element;
  28. }
  29. }
  30. $s = implode(" + ", $array) . " = " . implode(" + ", $newArray);
  31. echo $s . "\n";
  32. }
  33. if (array_sum($array) == 100) {
  34. $s = implode(" + ", $array);
  35. echo $s." = 100. \n";
  36. }
  37. }
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
11 + 10 + 16 + 7 + 14 + 17 + 12 + 13 = 100. 
11 + 10 + 16 + 13 = 7 + 14 + 17 + 12
11 + 10 + 17 + 12 = 16 + 7 + 14 + 13
11 + 14 + 12 + 13 = 10 + 16 + 7 + 17
10 + 16 + 7 + 17 = 11 + 14 + 12 + 13
16 + 7 + 14 + 13 = 11 + 10 + 17 + 12
7 + 14 + 17 + 12 = 11 + 10 + 16 + 13
10 + 16 + 7 + 17 = 11 + 14 + 12 + 13
16 + 7 + 14 + 13 = 11 + 10 + 17 + 12
7 + 14 + 17 + 12 = 11 + 10 + 16 + 13
16 + 7 + 14 + 13 = 11 + 10 + 17 + 12
7 + 14 + 17 + 12 = 11 + 10 + 16 + 13
7 + 14 + 17 + 12 = 11 + 10 + 16 + 13