Skip to content

Instantly share code, notes, and snippets.

@geowa4
Created February 8, 2013 01:46
Show Gist options
  • Select an option

  • Save geowa4/4735956 to your computer and use it in GitHub Desktop.

Select an option

Save geowa4/4735956 to your computer and use it in GitHub Desktop.
Project Euler Problem #10
leastDivisor :: Integer -> Integer -> Integer
leastDivisor divisor n
| rem n divisor == 0 = divisor
| divisor^2 > n = n
| otherwise = leastDivisor (divisor+1) n
hasFactor :: Integer -> Bool
hasFactor 1 = False
hasFactor n = (leastDivisor 2 n) /= n
primes :: [Integer]
primes = [x | x <- [2..], not (hasFactor x)]
euler10 :: Integer
euler10 = sum $ takeWhile (<2000000) primes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment