Skip to content

Instantly share code, notes, and snippets.

@mresetar
Created September 12, 2011 22:30
Show Gist options
  • Save mresetar/1212660 to your computer and use it in GitHub Desktop.
Save mresetar/1212660 to your computer and use it in GitHub Desktop.
Euler problem two
int fib(int to, int fibMinOne=0, int fibMinTwo=0) {
to > 2 ? ((fibMinTwo==0 ? fib(to - 2):fibMinTwo) + (fibMinOne==0 ? fib (to - 1):fibMinOne)) : to == 2 ? 2: (to== 1 ? 1: 0);
}
int sum
int fibMinOne
int fibMinTwo
for (int i=0;; i++) { def f = fib(i,fibMinOne,fibMinTwo); fibMinTwo=fibMinOne;fibMinOne=f;if (f>4e6) break; sum+=f%2==0?f:0}
print sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment