euler/haskell/e003.hs

13 lines
610 B
Haskell
Raw Normal View History

2015-11-16 20:56:24 +01:00
-- 3 - largest prime factor
-- problem_3 :: Integer -> Integer
prims = fix (\f (x:xs) -> x:f (filter (\y -> rem y x /= 0) xs)) [2..]
get_prims :: Integer -> [Integer]
get_prims 1 = []
get_prims n = let p = head $ dropWhile (\x -> rem n x /= 0) prims
in p:get_prims (div n p)
--next_prim xs = head $ dropWhile (\y -> any (\e -> rem y e == 0) xs) [last xs + 1..]
--prims = filter (\x -> not $ any (\n -> rem x n == 0) [2..(x-1)]) [1..]
--pfactors n = [x | x <- takeWhile (\y -> y*y <= n) [2..], n `mod` x == 0, null $ pfactors x]
problem_3 :: Integer -> Integer
problem_3 x = last $ get_prims x