aboutsummaryrefslogtreecommitdiff
path: root/0010/main.hs
blob: 74780f517e347ec31b9bd6acc1709b010b4dc535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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