SHARE
TWEET

Day2New

vencinachev Oct 26th, 2019 128 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. type Student = (String, Int)
  2. s1 :: Student
  3. s2 :: Student
  4. s1 = ("Kiro Stamatov", 111213)
  5. s2 = ("Hristo Hristov", 102030)
  6.  
  7. mult4 :: (Int, Int, Int, Int) -> Int
  8. mult4 (x, y, z, t) = x*y*z*t
  9.  
  10. sort2 :: (Int, Int) -> (Int, Int)
  11. sort2 (x, y) = if x >= y then (x, y) else (y, x)
  12.  
  13. fib :: Int -> Int
  14. fib n
  15.     | n == 1 = 1
  16.     | n == 2 = 1
  17.     | n > 2  = fib (n-2) + fib (n-1)
  18.     | otherwise = error "Not defined"
  19.  
  20. fibStep :: (Int, Int) -> (Int, Int)
  21. fibStep (u, v) = (u, u+v)
  22.  
  23.  
  24. fibPair :: Int -> (Int, Int)
  25. fibPair n = (fib(n), fib(n + 1))
  26.  
  27. toEnd :: a -> [a] -> [a]
  28. toEnd x l = l ++ [x]
  29.  
  30. sumPairs :: [(Int, Int)] -> [Int]
  31. sumPairs pL = [x + y | (x, y) <- pL]
  32.  
  33. digit :: Char -> Bool
  34. digit ch = ch >= '0' && ch <= '9'
  35.  
  36. all_digits :: String -> String
  37. all_digits str = [ch | ch <- str,  digit ch]
  38.  
  39. allEven :: [Int] -> Bool
  40. allEven x = (x == [a | a <- x, even a])
  41.  
  42. allOdd :: [Int] -> Bool
  43. allOdd x = (x == [a | a <- x, odd a])
  44.  
  45. revWords :: String -> String
  46. revWords input = (unwords . reverse . words) input
  47.  
  48. sumMy :: [Int] -> Int
  49. sumMy [] = 0
  50. sumMy (x:xs) = x + sum xs
  51.  
  52. concatMy :: [[a]] -> [a]
  53. concatMy [] = []
  54. concatMy (x : xs) = x ++ concat xs
  55.  
  56. sumList :: [Int] -> Int
  57. sumList [] = 0
  58. sumList (x:xs) = x + sumList xs
  59.  
  60. concatList :: [[a]] -> [a]
  61. concatList [] = []
  62. concatList (x : xs) = x ++ concatList xs
  63.  
  64. member :: Int -> [Int] -> Bool
  65. member x [] = False
  66. member x (y:ys) = (x == y) || (member x ys)
  67.  
  68. plus1 :: [Int] -> [Int]
  69. plus1 [] = []
  70. plus1 (x:xs) = x + 1 : plus1 xs
  71.  
  72. filterEven :: [Int] -> [Int]
  73. filterEven [] = []
  74. filterEven (x:xs)
  75.     | even x    = x : filterEven xs
  76.     | otherwise = filterEven xs
  77.    
  78.  
  79. filterMy :: (Int -> Bool) -> [Int] -> [Int]
  80. filterMy p [] = []
  81. filterMy p (x:xs)
  82.     | p x       = x : filterMy p xs
  83.     | otherwise = filterMy p xs
  84.  
  85. insert :: Int -> [Int] -> [Int]
  86. insert x [] = [x]
  87. insert x (y:ys)
  88.     | x <= y = x : (y:ys)
  89.     | otherwise = y : insert x ys
  90.  
  91. insertSort :: [Int] -> [Int]
  92. insertSort [] = []
  93. insertSort (x:xs) = insert x (insertSort 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