Skip to content

Instantly share code, notes, and snippets.

@sleepynate
Forked from crebma/PrimeFactors.hs
Last active December 28, 2015 03:02
Show Gist options
  • Save sleepynate/5a3f0be0ca1d5ec1c820 to your computer and use it in GitHub Desktop.
Save sleepynate/5a3f0be0ca1d5ec1c820 to your computer and use it in GitHub Desktop.
module PrimeFactors (primeFactors) where
primeFactors :: Integer -> [Integer]
primeFactors 1 = []
primeFactors x = primeFactors' x 2
where primeFactors' x n
| x < n = []
| x `mod` n == 0 && x > n = [n] ++ primeFactors' (x `div` n, n + 1)
| otherwise = [x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment