Skip to content

Instantly share code, notes, and snippets.

@fbiville
Last active August 29, 2015 14:12
Show Gist options
  • Save fbiville/4d26989e6f9919a6c77b to your computer and use it in GitHub Desktop.
Save fbiville/4d26989e6f9919a6c77b to your computer and use it in GitHub Desktop.
primes :: Int -> Int
primes index = last (_primes 0 (index-1) [2] [3,5..])
_primes :: Int -> Int -> [Int] -> [Int] -> [Int]
_primes cur max p x
| cur >= max = p
| otherwise =
let x0 = head x in
_primes (cur+1) max (p++[x0]) (filter (\n -> n `mod` x0 /= 0) (tail x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment