Created
December 29, 2011 13:22
-
-
Save alg/1534092 to your computer and use it in GitHub Desktop.
Primes from 1 to N
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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