Created
February 13, 2013 13:10
-
-
Save zephiransas/4944491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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