Created
August 3, 2009 02:32
-
-
Save jvantuyl/160333 to your computer and use it in GitHub Desktop.
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(perms). | |
-export([perms/1]). | |
% Calculate the Permutations of a list | |
perms([]) -> [[]]; | |
perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])]. |
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(sieve). | |
-export([primes/1]). | |
sieve([]) -> []; | |
sieve([H|T]) -> [H|sieve([X||X<-T,X rem H =/= 0])]. | |
count(X) -> | |
count(X,[]). | |
count(X,L) when X >= 2 -> | |
count(X - 1,[X | L]); | |
count(X,L) when X < 2 -> | |
L. | |
% Find primes less than X using the Sieve of Eratosthenes | |
primes(X) -> | |
sieve(count(X)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment