challenges/e3/e3.hs

12 lines
295 B
Haskell
Raw Permalink Normal View History

2011-10-21 23:18:31 +02:00
factor n divisor
2011-10-22 18:44:33 +02:00
| (divisor >= n-1 || n == 1) = [n]
| rem n divisor == 0 = (factor (n `div` divisor) 2) ++ (factor divisor 2)
2011-10-21 23:18:31 +02:00
| otherwise = factor n (divisor+1)
2011-10-22 18:44:33 +02:00
mymax [] acc = acc
mymax (x:xs) acc
| x > acc = mymax xs x
| otherwise = mymax xs acc
e3 = mymax (factor 600851475143 2) 0