summaryrefslogtreecommitdiff
path: root/31-41/41.hs
diff options
context:
space:
mode:
Diffstat (limited to '31-41/41.hs')
-rw-r--r--31-41/41.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/31-41/41.hs b/31-41/41.hs
new file mode 100644
index 0000000..16fd51f
--- /dev/null
+++ b/31-41/41.hs
@@ -0,0 +1,16 @@
+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]
+
+goldbachList :: Int -> Int -> [(Int, Int)]
+goldbachList' :: Int -> Int -> Int -> [(Int, Int)]
+
+goldbachList l r = map goldbach $ filter even $ dropWhile (< 4) [l..r]
+goldbachList' l r i = filter (\(a, b) -> a > i && b > i) $ goldbachList l r