public
Created

Project Euler - Problem 3

  • Download Gist
euler-003.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11
import ONeillPrimes(primes)
 
result = iter n $ f n primes
where iter x (p:prs)
| p == x = p
| otherwise = let next = x `div` p
in iter next
$ f next (p:prs)
f n = dropWhile
(not . (== 0) . (n `mod`))
n = 600851475143

Why (\n x -> n `mod` x == 0) n when you can write just (\x -> n `mod` x == 0) ?

The predicate not . (\n x -> n `mod` x == 0) n can even be written without lambda:
not . (== 0) . (n `mod`)

Thanks for your suggestion. I wouldn't have thought of composing the two partially applied functions not . (== 0) . (n mod). I will correct the gist.
Actually, I wrote the code more than two years ago while starting to learn Haskell.
http://blog.opicasso.com/project-euler-problem-3

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.