Skip to content

Commit 8ad9559

Browse files
committed
ENH euler 7
1 parent 1d21f58 commit 8ad9559

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

euler007.hs

+10
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)