Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Project Euler - Problem 3
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
@md2perpe

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`)

@oscarpica
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.