summaryrefslogblamecommitdiff
path: root/31-41/40.hs
blob: 9d9b2f7ecee6b413b90d84b65eaa7af87afe780c (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                                                  
isPrime :: Int -> Bool

isPrime 1 = False
isPrime x = and $ map (\y -> x `mod` y /= 0) $ fst $ span (\y -> y * y <= x) [2..]

goldbach :: Int -> (Int, Int)

goldbach x = head [(a, b) | a <- primes, let b = x - a, isPrime b]
    where primes = filterPrime[3..]
          filterPrime (p:xs) = p:filterPrime [x | x <- xs, x `mod` p /= 0]