From bc76d979fd60b31d11aa2adea52a03a36b5c2277 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Thu, 10 Apr 2025 01:17:48 +0800 Subject: Summation of Primes --- 0010/main.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 0010/main.hs 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 -- cgit v1.0