SHARE
TWEET

Untitled

a guest Apr 26th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----------------------------------------- Zadanie 1 ---------------------------------------------
  2. powerlist [] = [[]]
  3. powerlist (x:xs) = [x:sublist | sublist <- powerlist xs] ++ powerlist xs
  4. ----------------------------------------- Zadanie 2 ---------------------------------------------
  5. product xs ys = [x | x <- xs, elem x ys]
  6. ----------------------------------------- Zadanie 3 ---------------------------------------------
  7. sum xs ys = xs ++ [y | y <- ys, not (elem y xs)]
  8. ----------------------------------------- Zadanie 4 ---------------------------------------------
  9. {-
  10. a) 6 / (12 / (24 / (8 / 2))) = 3.0
  11.   6 / (foldr (/) 2 [12,24,8])
  12.   6 / ( 12 / (foldr (/) 2 [24,8]))
  13.   6 / ( 12 / (24 / (foldr (/) 2 [8])))
  14.   6 / ( 12 / (24 / ( 8 / (foldr (/) 2 []))))
  15.   6 / ( 12 / (24 / ( 8 / 2)))
  16.   6 / ( 12 / (24 /  4 ))
  17.   6 / ( 12 / 6 )
  18.   6 / 2
  19.   3
  20.  
  21. b) (1 > 2 && (3 > 2 && (5 == 5 && True))) = False
  22. c) (max 3 (max 6 (max 12 (max 4 (max 55 (max 11 18)))))) = 55
  23. d) (max 3 (max 6 (max 12 (max 4 (max 55 (max 11 81)))))) = 81
  24. e) ((((((10 + ((54 + 6) / 2)) / 2) + 4) / 2) + 24) / 2) = 18
  25. f) ((((((((54 + 2) / 2) + 4) / 2) + 10) / 2) + 6) / 2) = 9.5
  26. g) (((64 / 4) / 2) / 4) = 2
  27.   foldl (/) ( 64 / 4) [2, 4]
  28.   foldl (/) ( (64 / 4) / 2 ) [4]
  29.   foldl (/) ( ((64 / 4) / 2) / 4 ) []
  30.   ((16 / 2) / 4)
  31.   (8 / 4)
  32.   2
  33.  
  34. h) (2*(2*(2*8 + 1) + 2) + 3) = 75
  35. -}
  36. ----------------------------------------- Zadanie 5 ---------------------------------------------
  37. check x xs = (==0) $ foldl (\x y -> if x == y then 0 else x) x xs
  38. ----------------------------------------- Zadanie 6 ---------------------------------------------
  39. foldlmap f []       = []
  40. foldlmap f (x:xs)   = foldl (\x xs -> (f x):xs) [] (x:xs) --- !!!!!
  41.  
  42. foldrmap f []       = []
  43. foldrmap f (x:xs)   = foldr (\x xs -> (f x):xs) [] (x:xs)
  44. ----------------------------------------- Zadanie 7 ---------------------------------------------
  45. -- a)
  46. foldllast (x:xs) = foldl1 (\x y -> y) (x:xs)
  47. foldrlast (x:xs) = foldr1 (\x y -> y) (x:xs)
  48.  
  49. -- b)
  50. foldlhead (x:xs) = foldl1 (\x y -> x) (x:xs)
  51. foldrhead (x:xs) = foldr1 (\x y -> x) (x:xs)
  52.  
  53. -- c)
  54. foldlmax (x:xs) = foldl1 (\x y -> max x y) (x:xs)
  55. foldrmax (x:xs) = foldr1 (\x y -> max x y) (x:xs)
  56. ----------------------------------------- Zadanie 8 ---------------------------------------------
  57. tupleunzip [] = ([], [])
  58. tupleunzip xs = (map fst xs, map snd xs)
  59. ----------------------------------------- Zadanie 9 ---------------------------------------------
  60. f1 xs = map(\x -> x + 1) xs
  61. f2 xs = foldl1(\x y -> x - y) xs
  62. f3 xs = foldl1(\x y -> x + y) xs
  63. f4 a xs = map(\x -> if x == a then True else False) xs
  64. f5 a xs = map(\x -> if x /= a then True else False) xs
  65. f6 xs = map (\x -> x:xs++[x]) xs
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top