Created
June 2, 2016 02:06
-
-
Save eccstartup/cb69911c163649e5dd0991c27ae102b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PrimeFactors where | |
lessFacs1 n = [k | k <- [2..(truncate (sqrt (fromInteger n)))], mod n k == 0] | |
lessPrimeFacs [] n = [] | |
lessPrimeFacs (p:ps) n | |
| mod n p == 0 = p:(lessPrimeFacs (p:ps) (div n p)) | |
| otherwise = lessPrimeFacs ps n | |
lessFacs n = lessPrimeFacs (lessFacs1 n) n | |
factor 1 = [] | |
factor n | |
| lf == [] = [n] | |
| length lf == 1 = lf ++ [div n (head lf)] | |
| otherwise = lf | |
where lf = lessFacs n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment