diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-08-12 15:47:31 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-08-12 15:47:31 +0200 |
| commit | bb515e51d67f37ba9c6dfbd2fd0930be873a5ada (patch) | |
| tree | e86abea100d2c02a5dad7b6d5f0bf29c307bae04 /haskell/010-summation_of_primes.hs | |
| parent | 1879caa1dd80cb11dd62403663917ad4bf7cc68e (diff) | |
| download | project_euler-bb515e51d67f37ba9c6dfbd2fd0930be873a5ada.tar.gz project_euler-bb515e51d67f37ba9c6dfbd2fd0930be873a5ada.tar.bz2 project_euler-bb515e51d67f37ba9c6dfbd2fd0930be873a5ada.zip | |
haskell problems 007 -> 010
Diffstat (limited to 'haskell/010-summation_of_primes.hs')
| -rw-r--r-- | haskell/010-summation_of_primes.hs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/haskell/010-summation_of_primes.hs b/haskell/010-summation_of_primes.hs new file mode 100644 index 0000000..e8d8015 --- /dev/null +++ b/haskell/010-summation_of_primes.hs @@ -0,0 +1,16 @@ +-- Summation of primes + +-- Problem 10 +-- The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. + +-- Find the sum of all the primes below two million. + + +main = do + print (sum $ eratos_sieve [2..1999999]) + +eratos_sieve :: [Int] -> [Int] +eratos_sieve [] = [] +eratos_sieve (x:xs) + | x * x > last xs = x:xs + | otherwise = x:eratos_sieve [n | n <- xs, n `mod` x /= 0] |
