Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.Char
  2.  
  3. zad2a 0 =  0
  4. zad2a 1 =  5
  5. zad2a n = zad2a (n-1) + 2*(zad2a (n-2))
  6.  
  7. zad2b 0 =  0
  8. zad2b 1 =  5
  9. zad2b n = f n 0 5 0
  10.     where f k x0 x1 acc
  11.         | k==1 = acc
  12.         | otherwise = f (k-1) x1 (x1+(2*x0)) (x1+(2*x0))
  13.        
  14. zad3a x
  15.     | length x < 2 = error "List dosen't have at least 2 elements"
  16.     | otherwise = [head (tail x)] ++ [head x] ++ drop 2 x
  17.    
  18. zad3b x
  19.     | length x < 2 = error "List dosen't have at least 2 elements"
  20.     | otherwise = [x !! (length x -1)] ++  take (length x -2) (tail x) ++ [head x]
  21.    
  22. zad3c x
  23.     | length x < 4 = error "List dosen't have at least 4 elements"
  24.     | otherwise = [head x] ++ [x !! (length x -2)] ++ take (length x - 4) (drop 2 x) ++ [x !! 1] ++ [last x]
  25.    
  26.  
  27. zad4 list a = f list a 0
  28.     where
  29.     f [] el n = n
  30.     f (x:xs) el n
  31.         | x == el = f xs el (n+1)
  32.         | otherwise = f xs el n
  33.  
  34. zad5 x y
  35.     | length x /= length y = False
  36.     | otherwise = all (\x -> x== True) (zipWith (==) x y)
  37.    
  38. zad6 x y
  39.     | length x /= length y = False
  40.     | otherwise = f x y
  41.     where
  42.     f [] b = True
  43.     f a b
  44.         | elem (head a) b = f (tail a) b
  45.         | otherwise = False
  46.  
  47. wstaw x [] = [x]
  48. wstaw x (y:yx)
  49.     | x > y = y:(wstaw x yx)
  50.     | otherwise = x:y:yx
  51.  
  52. zad7a x = f x [] (length x)
  53.     where
  54.         f [] acc _ = acc
  55.         f (a:ax) acc x = f ax (wstaw a acc) (x-1)
  56.        
  57. zad7b x = g x (length x)
  58.     where g e k
  59.         | k == 0 = e
  60.         | otherwise = g (f e [] (length e)) (k-1)
  61.         where
  62.             f [] acc _ = acc
  63.             f (a:ax) acc n
  64.                 | n == 1 = acc++[a]
  65.                 | a > head ax = f ([a]++tail ax) (acc++[head ax]) (n-1)
  66.                 | otherwise = f (ax) (acc++[a]) (n-1)
  67.  
  68. zad8 x y = f x y []
  69.     where
  70.         f [] b acc = acc++b
  71.         f a [] acc = acc++a
  72.         f (a:ax) (b:bx) acc
  73.             | a < b = f ax (b:bx) (acc++[a])
  74.             | otherwise = f (a:ax) (bx) (acc++[b])
  75.            
  76.            
  77. pusta1 :: Eq a => [a] -> Bool
  78. pusta1 x = (x == [])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement