module Hw4 where
+import qualified Data.List as L
+
-- wholemeal programming
{- |
map' :: (a -> b) -> [a] -> [b]
map' f = foldr f' []
where f' x acc = (f x) : acc
+
+-- exercise 5
+-- Sieve of Sundaram
+
+cartProd :: [a] -> [b] -> [(a,b)]
+cartProd xs ys = [(x, y) | x <- xs, y <- ys]
+
+genList :: Integer -> [Integer]
+genList n = [1..n]
+
+sieveSundaram :: Integer -> [Integer]
+sieveSundaram n = map (\x -> (2*x + 1)) $ (L.\\) xs $ L.sort $ f (cartProd xs xs)
+ where xs = genList n
+ f ps = L.nub $ filter (<= n) $ map (\(i,j) -> i + j + 2*i*j) ps