Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Naive Prime Sieve
-module(prime).
-export([start/1]).
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