We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1d21f58 commit 8ad9559Copy full SHA for 8ad9559
euler007.hs
@@ -0,0 +1,10 @@
1
+main = print $ primes !! 10000 -- zero indexing; 10001st prime
2
+ where primes = 2 : filter (\n -> (length $ prime_factors n) == 1) [3,5..]
3
+
4
+prime_factors :: (Integral a) => a -> [a]
5
+prime_factors 1 = []
6
+prime_factors n
7
+ | factor == [] = [n]
8
+ | n < (head factor)^2 = [n] -- stop searching if sqrt n < head factor
9
+ | otherwise = factor ++ prime_factors (n `div` (head factor))
10
+ where factor = take 1 [x | x <- [2..n-1], n `rem` x == 0]
0 commit comments