Skip to content

Instantly share code, notes, and snippets.

@kcsongor
Created April 7, 2016 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcsongor/63e5a1d46394400efb06bf8cd5452e5c to your computer and use it in GitHub Desktop.
Save kcsongor/63e5a1d46394400efb06bf8cd5452e5c to your computer and use it in GitHub Desktop.
module Main where
import Data.Functor.Foldable
import Data.Maybe
g :: (Ord a, Num a) => (a, [[a]]) -> Prim [Maybe a] (a, [[a]])
g (n, xs)
| n `elem` concatMap (take 1) xs'
= Cons Nothing (n + 2, xs')
| otherwise
= Cons (Just n) (n + 2, iterate (+ (2 * n)) (n * n) : xs')
where xs' = map (dropWhile (< n)) xs
primes :: [Int]
primes = 2 : catMaybes (ana g (3, []))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment