Sunday, February 23, 2014

Perl solution to Project Euler's problem #2

http://projecteuler.net/problem=2
#!/usr/local/bin/perl
$fib1 = 1;
$fib2 = 2;
$sum = 1;
while ($fib2 < 4000000) {
  if($fib2 % 2 == 0){
    $sum += $fib2;
  }
  $aux = $fib2;
  $fib2 += $fib1;
  $fib1 = $aux;
}

print $sum;

1 comment:

Anonymous said...

5+5