import Prelude hiding (iterate)
fibs = 0:1:(zipWith (+) fibs (tail fibs))
fib 0 = 0
fib 1 = 1
fib x = fib (x - 1) + fib (x - 2)
fibs2 = [fib x | x <- [0..]]
fibs3 = map fib [0..]
iterate f x = x : iterate f (f x)
liste x = x : liste (x + 1)
fibs4 = map fst $ iterate (\(x,y) -> (y,x+y)) (0,1)
fibs5 = go 0 1
where go x y = x : go y (x+y)
merge [] ys = ys
merge xs [] = xs
merge (x:xs) (y:ys)
| x <= y = x : merge xs (y:ys)
| otherwise = y : merge (x:xs) ys
primes :: [Integer]
primes = sieve [2..]
sieve :: [Integer] -> [Integer]
sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p > 0]
--primepowers :: Integer -> [Integer]
--primepowers 1 = primes
--primepowers n = map (^n) primes `merge` primepowers (n-1)
--sum [] = 0
--sum (x:xs) = x + sum xs
--sum xs = foldr (+) 0 xs
--primepowers n = foldl merge [] [(map (^i) primes) | i <- [1..n]]
primepowers n = foldl1 merge [(map (^i) primes) | i <- [1..n]]
intersect :: Ord t => [t] -> [t] -> [t]
--intersect [] ys = []
--intersect xs [] = []
intersect (x:xs) (y:ys)
| x == y = x : intersect xs ys
| x < y = intersect xs (y:ys)
| otherwise = intersect (x:xs) ys
intersect xs ys = []
--intersectAll (l:ls) = foldr intersect l ls
intersectAll ls = foldr1 intersect ls
--commonMultiples = [105,210..]
-- where x = intersectAll [[]]
commonMultiples a b c = intersectAll [[a,2*a..], [b,2*b..], [c,2*c..]]
rand :: [Integer]
--rand = 32 : 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 :: [Integer] -> [Bool]
--toCoin xs = map (>= 2^15) xs
toCoin = map (>= 2^15)
neumann :: [Bool] -> [Bool]
neumann (x:y:xs)
| x == y = neumann xs
| otherwise = x : neumann xs
bias :: [Bool] -> [Bool]
bias (x:y:xs) = (x && y) : bias xs
go = do
--getRandom 5
r <- getRandom
r 5