20 lines
569 B
Haskell
20 lines
569 B
Haskell
module Lib (fib, primes, primeFactors) where
|
|
|
|
fib :: [Integer]
|
|
fib = 1 : 2 : zipWith (+) fib (tail fib)
|
|
|
|
isPrime :: Integer -> Bool
|
|
isPrime n = n > 1 && null [[] | k <- [2 .. (floor $ sqrt $ fromIntegral n)], mod n k == 0]
|
|
|
|
primes :: [Integer]
|
|
primes = 2 : filter isPrime [3, 4 ..]
|
|
|
|
primeFactors :: Integer -> [Integer]
|
|
primeFactors n = genPrimeFactors n 2
|
|
where
|
|
genPrimeFactors :: Integer -> Integer -> [Integer]
|
|
genPrimeFactors n c
|
|
| c * c > n = [n]
|
|
| mod n c /= 0 = genPrimeFactors n (c + 1)
|
|
| otherwise = c : genPrimeFactors (div n c) c
|