Skip to content

Instantly share code, notes, and snippets.

@gzmask
Created June 19, 2012 21:16
Show Gist options
  • Save gzmask/2956578 to your computer and use it in GitHub Desktop.
Save gzmask/2956578 to your computer and use it in GitHub Desktop.
project euler Problem 3
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
@gzmask
Copy link
Author

gzmask commented Jun 21, 2012

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