Skip to content

Instantly share code, notes, and snippets.

@geowa4
Created February 8, 2013 01:19
Show Gist options
  • Save geowa4/4735799 to your computer and use it in GitHub Desktop.
Save geowa4/4735799 to your computer and use it in GitHub Desktop.
Project Euler Problem #3
leastDivisor :: Integer -> Integer -> Integer
leastDivisor divisor n
| rem n divisor == 0 = divisor
| divisor^2 > n = n
| otherwise = leastDivisor (divisor+1) n
factors :: Integer -> [Integer]
factors 1 = []
factors n = ld : factors (n `div` ld)
where ld = leastDivisor 2 n
euler3 :: Integer
euler3 = maximum $ factors 600851475143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment