Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------- Zadanie 1 ---------------------------------------------
- powerlist [] = [[]]
- powerlist (x:xs) = [x:sublist | sublist <- powerlist xs] ++ powerlist xs
- ----------------------------------------- Zadanie 2 ---------------------------------------------
- product xs ys = [x | x <- xs, elem x ys]
- ----------------------------------------- Zadanie 3 ---------------------------------------------
- sum xs ys = xs ++ [y | y <- ys, not (elem y xs)]
- ----------------------------------------- Zadanie 4 ---------------------------------------------
- {-
- a) 6 / (12 / (24 / (8 / 2))) = 3.0
- 6 / (foldr (/) 2 [12,24,8])
- 6 / ( 12 / (foldr (/) 2 [24,8]))
- 6 / ( 12 / (24 / (foldr (/) 2 [8])))
- 6 / ( 12 / (24 / ( 8 / (foldr (/) 2 []))))
- 6 / ( 12 / (24 / ( 8 / 2)))
- 6 / ( 12 / (24 / 4 ))
- 6 / ( 12 / 6 )
- 6 / 2
- 3
- b) (1 > 2 && (3 > 2 && (5 == 5 && True))) = False
- c) (max 3 (max 6 (max 12 (max 4 (max 55 (max 11 18)))))) = 55
- d) (max 3 (max 6 (max 12 (max 4 (max 55 (max 11 81)))))) = 81
- e) ((((((10 + ((54 + 6) / 2)) / 2) + 4) / 2) + 24) / 2) = 18
- f) ((((((((54 + 2) / 2) + 4) / 2) + 10) / 2) + 6) / 2) = 9.5
- g) (((64 / 4) / 2) / 4) = 2
- foldl (/) ( 64 / 4) [2, 4]
- foldl (/) ( (64 / 4) / 2 ) [4]
- foldl (/) ( ((64 / 4) / 2) / 4 ) []
- ((16 / 2) / 4)
- (8 / 4)
- 2
- h) (2*(2*(2*8 + 1) + 2) + 3) = 75
- -}
- ----------------------------------------- Zadanie 5 ---------------------------------------------
- check x xs = (==0) $ foldl (\x y -> if x == y then 0 else x) x xs
- ----------------------------------------- Zadanie 6 ---------------------------------------------
- foldlmap f [] = []
- foldlmap f (x:xs) = foldl (\x xs -> (f x):xs) [] (x:xs) --- !!!!!
- foldrmap f [] = []
- foldrmap f (x:xs) = foldr (\x xs -> (f x):xs) [] (x:xs)
- ----------------------------------------- Zadanie 7 ---------------------------------------------
- -- a)
- foldllast (x:xs) = foldl1 (\x y -> y) (x:xs)
- foldrlast (x:xs) = foldr1 (\x y -> y) (x:xs)
- -- b)
- foldlhead (x:xs) = foldl1 (\x y -> x) (x:xs)
- foldrhead (x:xs) = foldr1 (\x y -> x) (x:xs)
- -- c)
- foldlmax (x:xs) = foldl1 (\x y -> max x y) (x:xs)
- foldrmax (x:xs) = foldr1 (\x y -> max x y) (x:xs)
- ----------------------------------------- Zadanie 8 ---------------------------------------------
- tupleunzip [] = ([], [])
- tupleunzip xs = (map fst xs, map snd xs)
- ----------------------------------------- Zadanie 9 ---------------------------------------------
- f1 xs = map(\x -> x + 1) xs
- f2 xs = foldl1(\x y -> x - y) xs
- f3 xs = foldl1(\x y -> x + y) xs
- f4 a xs = map(\x -> if x == a then True else False) xs
- f5 a xs = map(\x -> if x /= a then True else False) xs
- f6 xs = map (\x -> x:xs++[x]) xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement