euler/haskell/e012.hs

37 lines
833 B
Haskell
Raw Normal View History

2015-01-04 23:52:50 +01:00
import Data.List
divisor_count :: Integer -> Int
divisor_count n = length [x | x <- [1..n], rem n x == 0]
--triangles :: [Integer]
--triangles = undefined
triag :: [Integer]
triag = triag' 1 2
where triag' s i = s:(triag' (s+i) (i+1))
rest60 :: Integer -> Integer
rest60 x = rem x 60
atkin :: Int -> [Integer]
atkin = undefined
prims :: Integer -> [Integer]
prims n = eres [2..n]
where
eres (x:xs)
| x*x > n = (x:xs)
| otherwise = x:eres (filter (\y -> rem y x /= 0) xs)
prim_factors :: Integer -> [Integer]
prim_factors 1 = []
prim_factors x = p:prim_factors (quot x p)
where p = head $ filter (\y -> rem x y == 0) (prims x)
--divisor_count' :: Integer -> Int
divisor_count' x = product . map (succ . length) . group $ prim_factors x
main = do
putStrLn . show $ filter (\x -> divisor_count' x >= 500) triag