Created
June 19, 2012 21:16
-
-
Save gzmask/2956578 to your computer and use it in GitHub Desktop.
project euler Problem 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| num = 600851475143 | |
| nums = reverse [1..600851475143] | |
| isPrime :: (Integral a) => a -> Bool | |
| isPrime x = (product $ map (mod x) [2..(x-1)]) /= 0 | |
| getPrimes :: (Integral a) => [a] -> [a] | |
| getPrimes xs = filter isPrime $ xs | |
| primes = getPrimes nums | |
| isFactor :: (Integral a) => a -> a -> Bool | |
| isFactor x y = (mod x y) == 0 | |
| largestPrimeFactor = find (isFactor num) $ primes |
Author
thanks! "and" is short-circuit and use sqrt to reduce n to sqrt(n). this works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You shuold modify your
isPrimetoo.Here is mine: