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/41.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 31-41/41.hs (limited to '31-41/41.hs') 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 -- cgit v1.2.3