haskell: add [p4, p10]
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
module Lib (fib, primeFactors) where
|
||||
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 == n = [n]
|
||||
| c * c > n = [n]
|
||||
| mod n c /= 0 = genPrimeFactors n (c + 1)
|
||||
| otherwise = c : genPrimeFactors (div n c) c
|
||||
|
Reference in New Issue
Block a user