Skip to content

Instantly share code, notes, and snippets.

@kubek2k
Created April 12, 2014 21:59
Show Gist options
  • Save kubek2k/10558929 to your computer and use it in GitHub Desktop.
Save kubek2k/10558929 to your computer and use it in GitHub Desktop.
Primes in haskell
module Main where
primes = 1:(nextPrime 2 [])
divisibleByAny x numbers = any (\n -> (rem x n) == 0) numbers
nextPrime start primesSoFar = let
nextP = head (dropWhile (\x -> divisibleByAny x primesSoFar) [start..])
in
nextP:(nextPrime (nextP + 1) (nextP:primesSoFar))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment