/*
 * Copyright 2015 Olivier Grégoire <fror@users.noreply.github.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package be.fror.projecteuler.problem;

/**
 * <p>
 * Each new term in the Fibonacci sequence is generated by adding the previous two terms. By
 * starting with 1 and 2, the first 10 terms will be:</p>
 * <p style="text-align:center;">1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...</p>
 * <p>
 * By considering the terms in the Fibonacci sequence whose values do not exceed four million, find
 * the sum of the even-valued terms.</p>
 * 
 * @author Olivier Grégoire &lt;fror@users.noreply.github.com&gt;
 */
public class Problem2 extends AbstractProblem {

  @Override
  public Object solve() {
    final int N = 4000000;

    int sum = 0;

    for (int a = 1, b = 2, tmp; b <= N; tmp = a + b, a = b, b = tmp) {
      if ((b & 1) == 0) {
        sum += b;
      }
    }
    return sum;
  }

}

@@ -1054,17 +1054,16 @@
 .%3C/p%3E%0A *
- 
 %0A * @aut
@@ -1174,16 +1174,18 @@
 blem %7B%0A%0A
+  
   @Overr
@@ -1188,16 +1188,18 @@
 verride%0A
+  
   public
@@ -1212,24 +1212,28 @@
 t solve() %7B%0A
+    
     final in
@@ -1243,17 +1243,23 @@
  = 4
+_
 000
+_
 000;%0A%0A
+    
     
@@ -1276,16 +1276,20 @@
 0;%0A%0A    
+ 
+   
 for (int
@@ -1357,46 +1357,40 @@
     
-if ((b & 1) == 0) %7B%0A        sum += b;%0A
+      sum += b * (b & 1 %5E 1);%0A  
     
@@ -1393,26 +1393,24 @@
       %7D%0A    
-%7D%0A
     return s
@@ -1413,15 +1413,17 @@
 rn sum;%0A
+  
   %7D%0A%0A%7D%0A

Optimize problem 2