blob: 185d024e4b5d11bbced9376bec7eca93d8023736 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
|
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
|