summaryrefslogtreecommitdiff
path: root/haskell/p3.hs
diff options
context:
space:
mode:
Diffstat (limited to 'haskell/p3.hs')
-rw-r--r--haskell/p3.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/haskell/p3.hs b/haskell/p3.hs
new file mode 100644
index 0000000..f50c2de
--- /dev/null
+++ b/haskell/p3.hs
@@ -0,0 +1,9 @@
+p3 :: Integer
+p3 = maximum $ factors 600851475143 []
+ where
+ factors :: Integer -> [Integer] -> [Integer]
+ factors 1 l = l
+ factors n l = factors (div n divisor) (divisor:l)
+ where divisor = head $ filter (\x -> mod n x == 0) [2..]
+
+main = putStrLn $ "Solution: " ++ show p3