Skip to content

Instantly share code, notes, and snippets.

@crebma
Last active December 28, 2015 02:56
Show Gist options
  • Save crebma/3e54339aada256018f1e to your computer and use it in GitHub Desktop.
Save crebma/3e54339aada256018f1e 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