import Data.Numbers.Primes
merge (x:xs) (y:ys)
| x < y = x : merge xs (y:ys)
| otherwise = y : merge (x:xs) ys
merge xs ys = xs ++ ys
merge2 xs ys = reverse (merge' (reverse xs) (reverse ys))
where merge' (x:xs) (y:ys)
| x > y = x : merge' xs (y:ys)
| otherwise = y : merge' (x:xs) ys
merge' xs ys = xs ++ ys
primepowers :: Integer -> [Integer]
primepowers n
| n == 1 = primes
| otherwise = merge (map (^n) primes) (primepowers (n-1))
primepowers' n = foldr (\x ps -> merge ps (map (^x) primes)) [] [1..n]
primepowers'' n = foldr merge [] [map (^i) primes | i <- [1..n]]
intersect :: (Ord t) => [t] -> [t] -> [t]
intersect (x:xs) (y:ys)
| x < y = intersect xs (y:ys)
| x > y = intersect (x:xs) ys
| x == y = x : intersect xs ys
intersect xs ys = []
intersectAll :: (Ord t) => [[t]] -> [t]
intersectAll [] = []
--intersectAll [x] = x
--intersectAll (x:xs) = intersect x (intersectAll xs)
intersectAll (x:xs) = foldr intersect x xs
--sum [] = 0
--sum (x:xs) = (+) x (sum xs)
--sum xs = foldr (+) 0 xs
multiplesOf = intersectAll [[2,4..],[3,6..],[7,14..]]
multiplesOf' = [42,84..]
rand :: [Integer]
--rand = x0 : map (\x -> (a * x + b) `mod` m) rand
rand = iterate (\x -> (a * x + b) `mod` m) x0
where m = 2^16
a = 25173
b = 13849
x0 = 32
--toCoin xs = map even xs
toCoin xs = map (>= 2^15) xs
neumann :: [Bool] -> [Bool]
neumann (x:y:xs)
| x /= y = x : neumann xs
| otherwise = neumann xs
neumann xs = error "No infinite list"
--bias :: [Bool] -> [Bool]
--bias (x:y:xs)
-- | x == y && x == True = x : bias xs
-- | otherwise = False : bias xs
--bias (x:y:xs)
-- | y == True = x : bias xs
-- | otherwise = False : bias xs
bias (x:y:xs) = (x && y) : bias xs