From 9db0008777cc4cd9f07e14a3458e3d903e3cc4f6 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 29 May 2017 13:29:11 -0400 Subject: finish vol 4 --- 31-41/40.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 31-41/40.hs (limited to '31-41/40.hs') diff --git a/31-41/40.hs b/31-41/40.hs new file mode 100644 index 0000000..9d9b2f7 --- /dev/null +++ b/31-41/40.hs @@ -0,0 +1,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] -- cgit v1.2.3