Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Char
- zad2a 0 = 0
- zad2a 1 = 5
- zad2a n = zad2a (n-1) + 2*(zad2a (n-2))
- zad2b 0 = 0
- zad2b 1 = 5
- zad2b n = f n 0 5 0
- where f k x0 x1 acc
- | k==1 = acc
- | otherwise = f (k-1) x1 (x1+(2*x0)) (x1+(2*x0))
- zad3a x
- | length x < 2 = error "List dosen't have at least 2 elements"
- | otherwise = [head (tail x)] ++ [head x] ++ drop 2 x
- zad3b x
- | length x < 2 = error "List dosen't have at least 2 elements"
- | otherwise = [x !! (length x -1)] ++ take (length x -2) (tail x) ++ [head x]
- zad3c x
- | length x < 4 = error "List dosen't have at least 4 elements"
- | otherwise = [head x] ++ [x !! (length x -2)] ++ take (length x - 4) (drop 2 x) ++ [x !! 1] ++ [last x]
- zad4 list a = f list a 0
- where
- f [] el n = n
- f (x:xs) el n
- | x == el = f xs el (n+1)
- | otherwise = f xs el n
- zad5 x y
- | length x /= length y = False
- | otherwise = all (\x -> x== True) (zipWith (==) x y)
- zad6 x y
- | length x /= length y = False
- | otherwise = f x y
- where
- f [] b = True
- f a b
- | elem (head a) b = f (tail a) b
- | otherwise = False
- wstaw x [] = [x]
- wstaw x (y:yx)
- | x > y = y:(wstaw x yx)
- | otherwise = x:y:yx
- zad7a x = f x [] (length x)
- where
- f [] acc _ = acc
- f (a:ax) acc x = f ax (wstaw a acc) (x-1)
- zad7b x = g x (length x)
- where g e k
- | k == 0 = e
- | otherwise = g (f e [] (length e)) (k-1)
- where
- f [] acc _ = acc
- f (a:ax) acc n
- | n == 1 = acc++[a]
- | a > head ax = f ([a]++tail ax) (acc++[head ax]) (n-1)
- | otherwise = f (ax) (acc++[a]) (n-1)
- zad8 x y = f x y []
- where
- f [] b acc = acc++b
- f a [] acc = acc++a
- f (a:ax) (b:bx) acc
- | a < b = f ax (b:bx) (acc++[a])
- | otherwise = f (a:ax) (bx) (acc++[b])
- pusta1 :: Eq a => [a] -> Bool
- pusta1 x = (x == [])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement