Skip to content

Instantly share code, notes, and snippets.

@stephenpaulger
Created April 7, 2010 16:55
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 stephenpaulger/359124 to your computer and use it in GitHub Desktop.
Save stephenpaulger/359124 to your computer and use it in GitHub Desktop.
-module(sieve).
-export([sieve/1]).
sieve(N) ->
[1 | sieve(lists:seq(2, N), N)].
sieve([Head|L], N) when Head * 2 < N ->
[Head | sieve(L -- lists:seq(Head * 2, N, Head), N)];
sieve([Head|L], _) ->
[Head | L].
@stephenpaulger
Copy link
Author

  1. view Started with some experiments in the Erlang shell.
  2. view Created a recursive implementation based on my experiments
  3. view Reformatted to make it more readable.
  4. view Change to use a more common way of adding items to the head of a list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment