Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Created January 27, 2012 15:59
Show Gist options
  • Save stepankuzmin/1689461 to your computer and use it in GitHub Desktop.
Save stepankuzmin/1689461 to your computer and use it in GitHub Desktop.
Project Euler. Problem 7.
-module(euler7).
-export([start/0]).
start() ->
start_acc(2, 0).
start_acc(N, 10001) ->
N-1;
start_acc(N, Acc) ->
case is_prime(N) of
true -> start_acc(N+1, Acc+1);
false -> start_acc(N+1, Acc)
end.
is_prime(N) ->
is_prime_acc(N, N-1).
is_prime_acc(_, 1) ->
true;
is_prime_acc(N, M) when N rem M == 0 ->
false;
is_prime_acc(N, M) ->
is_prime_acc(N, M-1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment