SHARE
TWEET

Day1

vencinachev Oct 25th, 2019 135 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cube :: Int -> Int
  2. cube x = x*x*x
  3.  
  4. mult2 :: Int -> Int -> Int
  5. mult2 x y = x*y
  6.  
  7. -- Дефиниране на величина
  8. size :: Int
  9. size = 10
  10.  
  11. square :: Int -> Int
  12. square x = x*x
  13.  
  14. add2 :: Int -> Int -> Int
  15. add2 x y = x+y
  16.  
  17. mult3 :: Int -> Int -> Int -> Int
  18. mult3 x y z = x*y*z
  19.  
  20. max2 :: Int -> Int -> Int
  21. max2 x y
  22.     | x >= y     = x
  23.     | otherwise  = y
  24.  
  25. max3 :: Int -> Int -> Int -> Int
  26. max3 x y z
  27.     | x >= y && x >= z = x
  28.     | y >= z           = y
  29.     | otherwise        = z
  30.  
  31. fact :: Int -> Int
  32. fact n
  33.     | n == 0 = 1
  34.     | n > 0  = n * fact(n-1)
  35.  
  36.  
  37. inc :: Int -> Int
  38. inc = add2 1
  39.  
  40. max2if :: Int -> Int -> Int
  41. max2if x y = if x >= y then x else y
  42.  
  43. add2nc :: (Int, Int) -> Int
  44. add2nc (x, y) = x+y
  45.  
  46.  
  47. f :: Float -> Float -> Float
  48. f x y =
  49.     a^3 + b^2*a - b^3*x*y
  50.     where
  51.     a :: Float
  52.     a = 1 + x^6*y^3
  53.     b :: Float
  54.     b = x^2 + y^3
  55.  
  56. solveqe :: Float -> Float -> Float -> [Float]
  57. solveqe a b c
  58.     | d < 0 = []
  59.     | otherwise = [(-b + sqrt d) / (2*a), (-b - sqrt d)/ (2*a)]
  60.     where
  61.     d :: Float
  62.     d = b*b - 4*a*c
  63.    
  64. f1 :: Float -> Float -> Float
  65. f1 x y
  66.     | cube_x > cube_y = cube_x
  67.     | otherwise       = cube_y
  68.     where
  69.     cube_x = cb x
  70.     cube_y = cb y
  71.     cb :: Float -> Float
  72.     cb a = a^3
  73.  
  74. f2 :: Int -> Int -> Int
  75. f2 x y =
  76.     let
  77.         cb :: Int -> Int;
  78.         cb a = a*a*a;
  79.         cube_x = cb x
  80.         cube_y = cb y
  81.         in
  82.         if cube_x > cube_y then cube_x else cube_y
  83.  
  84. solveqe1 :: Float -> Float -> Float -> [Float]
  85. solveqe1 a b c =
  86.     let
  87.         d = b*b - 4*a*c
  88.     in
  89.     if d > 0 then [((-b + sqrt d)/(2*a)), ((-b - sqrt d)/ (2*a))] else []
  90.  
  91. exOr :: Bool -> Bool -> Bool
  92. exOr a b = (a && not b) || (not a && b)
  93.  
  94. myNot :: Bool -> Bool
  95. myNot True = False
  96. myNot False = True
  97.  
  98. threeEqual :: Int -> Int -> Int -> Bool
  99. threeEqual x y z = (x == y) && (y == z)
  100.  
  101. isDigit :: Char -> Bool
  102. isDigit ch = ('0' <= ch) && (ch <= '9')
  103.  
  104. facte :: Integer -> Integer
  105. facte n
  106.     | n == 0 = 1
  107.     | n > 0  = n*facte(n-1)
  108.     | otherwise = error "not defined"
  109.    
  110.  
  111. -- ex 1a
  112. max2e :: Int -> Int -> Int
  113. max2e x y = if x > y then x else y
  114.  
  115. min2e :: Int -> Int -> Int
  116. min2e x y = if x < y then x else y
  117.  
  118. func :: Int -> Int -> Int -> Int -> Int
  119. func a b c d = max2e (min2e a b) (min2e c d)
  120.  
  121. -- ex 1b
  122.  
  123.  
  124. areatr :: Float -> Float -> Float -> Float
  125. areatr a b c =
  126.         let p = (a + b + c) / 2
  127.         in sqrt (p*(p - a)*(p - b)*(p - c))
  128.  
  129.  
  130.  
  131.  
  132. -- ex 3
  133.  
  134. {- points :: Int -> Int
  135. points x =
  136.     if x == 1 then 10
  137.     else if x == 2 then 7
  138.     else if x == 3 then 5
  139.     else if x == 4 then 4
  140.     else if x == 5 then 3
  141.     else if x == 6 then 2
  142.     else if x == 7 then 1
  143.     else 0                   -}
  144. {-
  145. points :: Int -> Int
  146. points 1 = 10
  147. points 2 = 7
  148. points 3 = 5
  149. points 4 = 4
  150. points 5 = 3
  151. points 6 = 2
  152. points 7 = 1
  153. points _ = 0
  154. -}
  155.  
  156. points :: Int -> Int
  157. points 1 = 10
  158. points 2 = 7
  159. points x
  160.     | x <= 7     = 8 - x
  161.     | otherwise  = 0
  162.  
  163. -- ex 4
  164. isUppere, isLowere, isAlphae :: Char -> Bool
  165. isUppere c = c >= 'A' && c <= 'Z'
  166. isLowere c = c >= 'a' && c <= 'z'
  167. isAlphae c = isUppere c || isLowere c
  168.  
  169.  
  170. fastPower :: Int -> Int -> Int
  171. fastPower base power
  172.     | power == 0     = 1
  173.     | odd power      = (fastPower base (div power 2)) ^ 2 * base
  174.     | even power     = (fastPower base (div power 2)) ^ 2
  175.  
  176.  
  177. -- ex 7
  178. proot :: Float -> Int -> Float
  179. proot x p  = base x p x 0.01
  180.  
  181. base :: Float -> Int -> Float -> Float -> Float
  182. base x p prev eps
  183.     | abs (y - prev) < eps = y
  184.     | otherwise            = base x p y eps
  185.     where
  186.         y = 1 / (fromIntegral p) * (fromIntegral(p - 1) * prev + x / (prev ^ (p - 1)))
  187.  
  188.  
  189. digit2 :: Int -> Bool
  190. digit2 n
  191.     | n < 0     = digit2 (-n)
  192.     | n == 0    = False
  193.     | mod n 10 == 2 = True
  194.     | otherwise = digit2 (div n 10)
  195.  
  196.  
  197. digitn :: Int -> Int -> Bool
  198. digitn m n 
  199.     | (n < 0 || m < 0)    = digitn (abs m) (abs n)
  200.     | m == 0            = False
  201.     | mod m 10 == n         = True
  202.     | otherwise         = digitn (div m 10) n
  203.  
  204. -- ex 10
  205.  
  206. findy :: Float -> Float
  207. findy x = findy_iter 256 x x*x
  208.  
  209. findy_iter :: Int -> Float -> Float -> Float
  210. findy_iter 1 x y = x / y
  211. findy_iter i x y = findy_iter (div i 2) x ((fromIntegral i)/y+x*x)
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