Arina0904

Untitled

Sep 14th, 2022 (edited)
1,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List
  2.  
  3. myLast x = last x
  4.  
  5. my2 [] = error "empty"
  6. my2 [x] = error "net"
  7. my2 [a, b] = a
  8. my2 (x:xs) = my2 xs
  9.  
  10. my3 [] k = error "empty"
  11. my3 (x:xs) 1 = x  
  12. my3 (x:xs) k = if k > length (x:xs) then error"net" else my3 xs (k-1)
  13.  
  14. my4 x = length x
  15.  
  16. --my5 x = reverse x
  17. my5 [] =[]
  18. --my5 [a] = [a]
  19. --my5 [a,b] = [b,a]
  20. my5 (x:xs) = (my5 xs) ++ [x]
  21.  
  22.  
  23. my6 x
  24.     | x == (reverse x) = True
  25.     |otherwise = False
  26.  
  27. data NestedList a = Elem a | List [NestedList a] deriving (Show, Eq)
  28. my7 (List []) = []
  29. my7 (Elem a) = [a]
  30. my7 (List (x:xs)) = (my7 x) ++ (my7 (List xs))
  31.  
  32. my8 [] = []
  33. my8 [a] = [a]
  34. my8 (x:y:xs)
  35.     |x == y = my8 (x:xs)
  36.     |otherwise = x:(my8 (y:xs))
  37.    
  38. myy8 x = map (head) (group x)
  39.  
  40. my9 x = group x
  41.  
  42. --my10 x = zipWith (:) (map (length) (group x)) (map (head) (group x))
  43.  
  44. my10 x = map (\l -> (length l, head l)) (group x)
  45.  
  46. data Tmp a = Single a | Multiple Int a deriving Show
  47. my11 :: Eq a => [a] -> [Tmp a]
  48. my11 x = map (\(l,r) -> if l == 1 then Single r else Multiple l r) (my10 x)
  49.  
  50. my12 [] = []
  51. my12 ((Single a):xs) = a : (my12 xs)
  52. my12 ((Multiple n a):xs) = (replicate n a) ++ (my12 xs)
Advertisement
Add Comment
Please, Sign In to add comment