Advertisement
vencinachev

Day3

Nov 16th, 2020
1,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sumL :: [Int] -> Int
  2. sumL [] = 0
  3. sumL (x:xs) = x + sumL xs
  4.  
  5. po10 :: Int -> Int
  6. po10 x = 10 * x
  7.  
  8. mapMy :: (Int->Int) -> [Int] -> [Int]
  9. mapMy f [] = []
  10. mapMy f (x:xs) = (f x) : mapMy f xs
  11.  
  12. isLast0 :: Int -> Bool
  13. isLast0 x
  14.     | mod x 10 == 0 = True
  15.     | otherwise     = False
  16.  
  17. filterMy :: (Int->Bool) -> [Int] -> [Int]
  18. filterMy p [] = []
  19. filterMy p (x:xs)
  20.     | p x == True = x : filterMy p xs
  21.     | otherwise   = filterMy p xs
  22.  
  23. filterMy2 :: (Int->Bool) -> [Int] -> [Int]
  24. filterMy2 p list = [n | n <- list, p n]
  25.  
  26. reverseMy :: [a] -> [a]
  27. reverseMy [] = []
  28. reverseMy (x:xs) = reverseMy xs ++ [x]
  29.  
  30. insert :: Int -> [Int] -> [Int]
  31. insert x [] = [x]
  32. insert x (y:ys)
  33.     | x <= y    = x:(y:ys)
  34.     | otherwise = y : insert x ys
  35.  
  36. insertSort :: [Int] -> [Int]
  37. insertSort [] = []
  38. insertSort (x:xs) = insert x (insertSort xs)
  39.  
  40. qSort :: [Int] -> [Int]
  41. qSort [] = []
  42. qSort (x:xs) = qSort (filter (<x) xs) ++ [x] ++ qSort (filter (>=x) xs)
  43.  
  44. repeated :: (a->a) -> Int -> (a->a)
  45. repeated f 1 = f
  46. repeated f n = \x -> f (repeated f (n - 1) x)
  47.  
  48. derive :: (Float->Float) -> (Float->Float)
  49. derive f = \x -> (f (x + dx) - f x) / dx
  50.     where dx = 0.01
  51.  
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement