Skip to content

Instantly share code, notes, and snippets.

@codyrioux codyrioux/prime.erl
Created Dec 29, 2011

What would you like to do?
Naive Prime Sieve
start(Max) -> io:format("Solution: ~p ~n", [sieve(lists:seq(2, Max), Max)]).
sieve([H|T], Max) -> if H * H > Max -> [H] ++ T; true -> [H] ++ sieve(mark(H, T), Max) end.
mark(X, List) -> lists:filter(fun(Y) -> (Y rem X =/= 0) end, List).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.