Skip to content

Instantly share code, notes, and snippets.

@nicolasbrugneaux
Created April 9, 2015 15:16
Show Gist options
  • Save nicolasbrugneaux/42981db898272ab7957d to your computer and use it in GitHub Desktop.
Save nicolasbrugneaux/42981db898272ab7957d to your computer and use it in GitHub Desktop.
-- problem 31
primes :: [Int]
primes = nextPrime [2..]
where nextPrime (p:xs) = p:nextPrime [x | x <- xs, x `mod` p > 0]
-- problem 35
primeFactors :: Int -> [Int]
primeFactors n = [ x | x <- (takeWhile (< n) primes), n `mod` x == 0 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment