challenges/e3/e3.hs

12 lines
295 B
Haskell

factor n divisor
| (divisor >= n-1 || n == 1) = [n]
| rem n divisor == 0 = (factor (n `div` divisor) 2) ++ (factor divisor 2)
| otherwise = factor n (divisor+1)
mymax [] acc = acc
mymax (x:xs) acc
| x > acc = mymax xs x
| otherwise = mymax xs acc
e3 = mymax (factor 600851475143 2) 0