diff options
author | Determinant <ted.sybil@gmail.com> | 2017-05-29 13:29:11 -0400 |
---|---|---|
committer | Determinant <ted.sybil@gmail.com> | 2017-05-29 13:29:11 -0400 |
commit | 9db0008777cc4cd9f07e14a3458e3d903e3cc4f6 (patch) | |
tree | af3891261924ae914ee3855e948b4d479f4d06de /31-41/36.hs | |
parent | fa1bf6c2eac1c9f7969ff29504c9f51b9ba48008 (diff) |
finish vol 4
Diffstat (limited to '31-41/36.hs')
-rw-r--r-- | 31-41/36.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/31-41/36.hs b/31-41/36.hs new file mode 100644 index 0000000..cb9d09a --- /dev/null +++ b/31-41/36.hs @@ -0,0 +1,15 @@ +import Data.List (group) + +primeFactors :: Int -> [Int] + +primeFactors x = factor x primes + where primes = filterPrime [2..] + filterPrime (p:xs) = p:filterPrime [x | x <- xs, x `mod` p /= 0] + factor x l@(p:xs) + | p > x = [] + | x `mod` p == 0 = p:factor (x `div` p) l + | otherwise = factor x xs + +primeFactorsMult :: Int -> [(Int, Int)] + +primeFactorsMult x = [(head l, length l) | l <- group $ primeFactors x] |