Skip to content

Instantly share code, notes, and snippets.

@codyrioux
Created December 29, 2011 20:52
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 codyrioux/1536142 to your computer and use it in GitHub Desktop.
Save codyrioux/1536142 to your computer and use it in GitHub Desktop.
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