aboutsummaryrefslogtreecommitdiff
path: root/0010/main.hs
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-04-10 01:17:48 +0800
committerMistivia <i@mistivia.com>2025-04-10 01:17:48 +0800
commitbc76d979fd60b31d11aa2adea52a03a36b5c2277 (patch)
treed87d85a97f7d8f29f74f81771375962e53ef8680 /0010/main.hs
parenta35ca0e5acf5ce33ff55d9ab2aab2fe84eca3b85 (diff)
Summation of Primes
Diffstat (limited to '0010/main.hs')
-rw-r--r--0010/main.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/0010/main.hs b/0010/main.hs
new file mode 100644
index 0000000..74780f5
--- /dev/null
+++ b/0010/main.hs
@@ -0,0 +1,20 @@
+primes = primesImpl 2 []
+ where
+ primesImpl :: Integer -> [Integer] -> [Integer]
+ primesImpl i primeList =
+ if isPrime then
+ i:(primesImpl (i+1) (primeList ++ [i]))
+ else
+ primesImpl (i+1) primeList
+ where
+ isPrime = isPrimeImpl primeList
+ where
+ isPrimeImpl [] = True
+ isPrimeImpl (x:xs) =
+ if i `mod` x == 0 then
+ False
+ else
+ isPrimeImpl xs
+
+main = do
+ putStrLn $ show $ sum $ takeWhile (<2000000) primes