DEV Community

Discussion on: Project Euler #2 - Even Fibonacci numbers

Collapse
 
stephanie profile image
Stephanie Handsteiner • Edited

Solved a few of the Euler challenges a few years ago (when I was still in high school, because what else would you do?) using PHP.

Solution: 4613732

$sum = 0;
$curr = 2;
$prev = 1;
$goal = 4000000;
while ($curr < $goal) {
if($curr % 2 == 0) {
$sum += $curr;
}
$tmp = $prev;
$prev = $curr;
$curr += $tmp;
}
echo $sum;