Created
October 8, 2013 15:38
-
-
Save qoelet/6886668 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
-- prime factorization | |
-- definitely needs improvement :X | |
getPrimeFactor :: Integer -> [Integer] -> (Integer, Integer) | |
getPrimeFactor n (p:ps) | n `mod` p == 0 = (p, (n `div` p)) | |
| otherwise = getPrimeFactor n ps | |
getPrimeFactors :: Integer -> [Integer] -> [Integer] | |
getPrimeFactors n s | not (result == 1) = factor : getPrimeFactors result s | |
| otherwise = [factor] | |
where | |
(factor, result) = getPrimeFactor n s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment