Skip to content

Instantly share code, notes, and snippets.

@alg
Created December 29, 2011 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alg/1534092 to your computer and use it in GitHub Desktop.
Save alg/1534092 to your computer and use it in GitHub Desktop.
Primes from 1 to N
-module(t1).
-export([primes/1]).
primes(N) -> primeA(1, N, []).
primeA(X, N, L) ->
if
X =:= 1 -> primeA(2, N, [1|L]);
X > N -> lists:reverse(L);
true ->
NL = case length([I || I <- L, X rem I =:= 0]) of
1 -> [X | L];
_ -> L
end,
primeA(X + 1, N, NL)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment