stephan23

Project Euler - problem 2

Jun 1st, 2012
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.32 KB | None | 0 0
  1. <?php
  2.     // My answer to http://projecteuler.net/problem=2
  3.     $tot = 0;
  4.     $nums = array(1);
  5.     $a = 0;
  6.     while ($a < 4000000) {
  7.                
  8.         $a = array_sum($nums);
  9.        
  10.         if ($a%2==0) {
  11.             $tot += $a;
  12.         }
  13.        
  14.         array_push($nums,$a);  
  15.        
  16.         if (count($nums)>2) {
  17.             array_shift($nums);
  18.         }
  19.        
  20.    
  21.     }
  22.     echo $tot;
  23.     exit;
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment