Create a gist now

Instantly share code, notes, and snippets.

@alg /t1.erl
Created Dec 29, 2011

What would you like to do?
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