Advertisement
Guest User

Untitled

a guest
Jul 9th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.41 KB | None | 0 0
  1. $values = array();
  2.  
  3. for ($i = 0; $i < 1000000; $i++) {
  4.     $values[] = rand(0, 1000);
  5. }
  6.  
  7. $max = 0;
  8. $maxi = 0;
  9. $n = 0;
  10. $m = 59;
  11. $sum = array_sum(array_slice($values, $n, $m));
  12.  
  13. for ($i = 0; $i < 999940; $i++) {
  14.     $n++;
  15.     $m++;
  16.  
  17.     if($sum > $max) {
  18.         $maxi = $i;
  19.         $max = $sum;
  20.     }
  21.  
  22.     $sum = $sum + $values[$m] - $values[$n];
  23. }
  24.  
  25. $maxValues = array_slice($values, $maxi, 60);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement