Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Created January 24, 2012 10:33
Show Gist options
  • Save stepankuzmin/1669525 to your computer and use it in GitHub Desktop.
Save stepankuzmin/1669525 to your computer and use it in GitHub Desktop.
Project Euler. Problem 2.
-module(euler2).
-export([start/0]).
start() ->
start_acc(0, 0).
start_acc(N, Acc) ->
F = fib(N),
if F > 4000000 -> Acc;
true -> if F rem 2 == 0 -> start_acc(N+1, Acc+F);
true -> start_acc(N+1, Acc)
end
end.
fib(0) ->
0;
fib(1) ->
1;
fib(N) ->
fib(N-1) + fib(N-2).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment