summaryrefslogtreecommitdiff
path: root/31-41/40.hs
diff options
context:
space:
mode:
Diffstat (limited to '31-41/40.hs')
-rw-r--r--31-41/40.hs10
1 files changed, 10 insertions, 0 deletions
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]