Skip to content

Instantly share code, notes, and snippets.

@zephiransas
Created February 13, 2013 13:10
Show Gist options
  • Save zephiransas/4944491 to your computer and use it in GitHub Desktop.
Save zephiransas/4944491 to your computer and use it in GitHub Desktop.
public class Problem2 {
public static void main(String... args) {
List<Integer> data = new ArrayList<>();
int ix = 0;
while (true) {
ix++;
int v = fib(ix);
if(v > 4_000_000) break;
data.add(v);
}
int value = data.stream().filter(e -> e % 2 == 0).reduce(0, (x, y) -> x + y);
System.out.println(value);
}
private static int fib(int x) {
if(x <= 1) return 1;
if(x == 2) return 2;
return fib(x - 2) + fib(x - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment