import Data.List filter2 f [] = ([],[]) filter2 f (h:t) = let (s1,s2) = filter2 f t in if f h then (h:s1,s2) else (s1,h:s2) fibs = genf 0 1 genf f1 f2 = f1 : (genf f2 $ f1+f2) fibs' = 0:1:zipWith (+) fibs' (tail fibs') diffFib = zipWith (-) evenFibs oddFibs where (evenFibs, oddFibs) = filter2 even fibs' data Dvojice a = Dva a (Dvojice a) | Nic deriving Show vyrob a b = Dva a b skonvertujSeznam [] = Nic skonvertujSeznam (h:t) = Dva h $ skonvertujSeznam t data GlobElem = Exact Char | WildCard | Any deriving Show type Glob = [GlobElem] char2glob '*' = WildCard char2glob '?' = Any char2glob c = Exact c string2glob = map char2glob matchGlob :: Glob -> String -> Bool matchGlob [] "" = True matchGlob (Exact c:glob) (x:xs) = if x == c then matchGlob glob xs else False matchGlob (Any:glob) (_:xs) = matchGlob glob xs matchGlob (WildCard:glob) xs = any (matchGlob glob) (tails xs) matchGlob _ _ = False -- rle [1,1,1,1,1,1,2,2,2] = [(5,1),(3,2)] rle s = map (\s@(x:_)-> (x, length s)) $ group s