fork download
  1. <?php
  2.  
  3. function divide($lo, $hi, &$m) {
  4.  
  5. $m = ($lo + $hi) >> 1;
  6. }
  7.  
  8. function combo($a, $b, &$c) {
  9.  
  10. $c = $a + $b;
  11. }
  12.  
  13. function divideEtImpera($arr, $lo, $hi, &$z) {
  14.  
  15. if($lo == $hi) {
  16.  
  17. $z = $arr[ $lo ];
  18.  
  19. } else {
  20. divide($lo, $hi, $m);
  21. divideEtImpera($arr, $lo, $m, $a);
  22. divideEtImpera($arr, $m + 1, $hi, $b);
  23. combo($a,$b,$z);
  24. }
  25. }
  26.  
  27. $arr = array(1,2,3,4,5,6,7,8,9,10);
  28.  
  29. divideEtImpera($arr, 0, sizeof($arr) - 1, $z);
  30. echo"Sum 1 + 2 + 3 + ...+ 10 = ". $z;
  31. ?>
  32.  
Success #stdin #stdout 0.02s 25936KB
stdin
Standard input is empty
stdout
Sum 1 + 2 + 3 + ...+ 10 = 55