fork download
  1. <?php
  2. $digits = range(10, 100, 10);
  3.  
  4. function find_100($digits, $current = array()){
  5. static $matches = [];
  6.  
  7. foreach ($digits as $key => $digit) {
  8.  
  9. if(array_sum($current)>100)
  10. break;
  11.  
  12. if (array_sum($current) + $digit == 100) {
  13. $match = $current;
  14. $match[] = $digit;
  15. sort($match);
  16. $matches[] = $match;
  17. }
  18.  
  19. if (count($digits) > 1) {
  20. $next_current = $current;
  21. $next_current[] = $digit;
  22.  
  23. $next_step_digits = $digits;
  24. unset($next_step_digits[$key]);
  25.  
  26. find_100(array_values($next_step_digits), $next_current);
  27. }
  28. }
  29.  
  30. if(empty($current)){
  31. return array_map("unserialize", array_unique(array_map("serialize", $matches)));
  32. }
  33. }
  34.  
  35. var_dump(find_100($digits));
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
array(10) {
  [0]=>
  array(4) {
    [0]=>
    int(10)
    [1]=>
    int(20)
    [2]=>
    int(30)
    [3]=>
    int(40)
  }
  [2]=>
  array(3) {
    [0]=>
    int(10)
    [1]=>
    int(20)
    [2]=>
    int(70)
  }
  [5]=>
  array(3) {
    [0]=>
    int(10)
    [1]=>
    int(30)
    [2]=>
    int(60)
  }
  [8]=>
  array(3) {
    [0]=>
    int(10)
    [1]=>
    int(40)
    [2]=>
    int(50)
  }
  [12]=>
  array(2) {
    [0]=>
    int(10)
    [1]=>
    int(90)
  }
  [18]=>
  array(3) {
    [0]=>
    int(20)
    [1]=>
    int(30)
    [2]=>
    int(50)
  }
  [23]=>
  array(2) {
    [0]=>
    int(20)
    [1]=>
    int(80)
  }
  [34]=>
  array(2) {
    [0]=>
    int(30)
    [1]=>
    int(70)
  }
  [43]=>
  array(2) {
    [0]=>
    int(40)
    [1]=>
    int(60)
  }
  [56]=>
  array(1) {
    [0]=>
    int(100)
  }
}