Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cube :: Int -> Int
- cube x = x*x*x
- mult2 :: Int -> Int -> Int
- mult2 x y = x*y
- -- Дефиниране на величина
- size :: Int
- size = 10
- square :: Int -> Int
- square x = x*x
- add2 :: Int -> Int -> Int
- add2 x y = x+y
- mult3 :: Int -> Int -> Int -> Int
- mult3 x y z = x*y*z
- max2 :: Int -> Int -> Int
- max2 x y
- | x >= y = x
- | otherwise = y
- max3 :: Int -> Int -> Int -> Int
- max3 x y z
- | x >= y && x >= z = x
- | y >= z = y
- | otherwise = z
- fact :: Int -> Int
- fact n
- | n == 0 = 1
- | n > 0 = n * fact(n-1)
- inc :: Int -> Int
- inc = add2 1
- max2if :: Int -> Int -> Int
- max2if x y = if x >= y then x else y
- add2nc :: (Int, Int) -> Int
- add2nc (x, y) = x+y
- f :: Float -> Float -> Float
- f x y =
- a^3 + b^2*a - b^3*x*y
- where
- a :: Float
- a = 1 + x^6*y^3
- b :: Float
- b = x^2 + y^3
- solveqe :: Float -> Float -> Float -> [Float]
- solveqe a b c
- | d < 0 = []
- | otherwise = [(-b + sqrt d) / (2*a), (-b - sqrt d)/ (2*a)]
- where
- d :: Float
- d = b*b - 4*a*c
- f1 :: Float -> Float -> Float
- f1 x y
- | cube_x > cube_y = cube_x
- | otherwise = cube_y
- where
- cube_x = cb x
- cube_y = cb y
- cb :: Float -> Float
- cb a = a^3
- f2 :: Int -> Int -> Int
- f2 x y =
- let
- cb :: Int -> Int;
- cb a = a*a*a;
- cube_x = cb x
- cube_y = cb y
- in
- if cube_x > cube_y then cube_x else cube_y
- solveqe1 :: Float -> Float -> Float -> [Float]
- solveqe1 a b c =
- let
- d = b*b - 4*a*c
- in
- if d > 0 then [((-b + sqrt d)/(2*a)), ((-b - sqrt d)/ (2*a))] else []
- exOr :: Bool -> Bool -> Bool
- exOr a b = (a && not b) || (not a && b)
- myNot :: Bool -> Bool
- myNot True = False
- myNot False = True
- threeEqual :: Int -> Int -> Int -> Bool
- threeEqual x y z = (x == y) && (y == z)
- isDigit :: Char -> Bool
- isDigit ch = ('0' <= ch) && (ch <= '9')
- facte :: Integer -> Integer
- facte n
- | n == 0 = 1
- | n > 0 = n*facte(n-1)
- | otherwise = error "not defined"
- -- ex 1a
- max2e :: Int -> Int -> Int
- max2e x y = if x > y then x else y
- min2e :: Int -> Int -> Int
- min2e x y = if x < y then x else y
- func :: Int -> Int -> Int -> Int -> Int
- func a b c d = max2e (min2e a b) (min2e c d)
- -- ex 1b
- areatr :: Float -> Float -> Float -> Float
- areatr a b c =
- let p = (a + b + c) / 2
- in sqrt (p*(p - a)*(p - b)*(p - c))
- -- ex 3
- {- points :: Int -> Int
- points x =
- if x == 1 then 10
- else if x == 2 then 7
- else if x == 3 then 5
- else if x == 4 then 4
- else if x == 5 then 3
- else if x == 6 then 2
- else if x == 7 then 1
- else 0 -}
- {-
- points :: Int -> Int
- points 1 = 10
- points 2 = 7
- points 3 = 5
- points 4 = 4
- points 5 = 3
- points 6 = 2
- points 7 = 1
- points _ = 0
- -}
- points :: Int -> Int
- points 1 = 10
- points 2 = 7
- points x
- | x <= 7 = 8 - x
- | otherwise = 0
- -- ex 4
- isUppere, isLowere, isAlphae :: Char -> Bool
- isUppere c = c >= 'A' && c <= 'Z'
- isLowere c = c >= 'a' && c <= 'z'
- isAlphae c = isUppere c || isLowere c
- fastPower :: Int -> Int -> Int
- fastPower base power
- | power == 0 = 1
- | odd power = (fastPower base (div power 2)) ^ 2 * base
- | even power = (fastPower base (div power 2)) ^ 2
- -- ex 7
- proot :: Float -> Int -> Float
- proot x p = base x p x 0.01
- base :: Float -> Int -> Float -> Float -> Float
- base x p prev eps
- | abs (y - prev) < eps = y
- | otherwise = base x p y eps
- where
- y = 1 / (fromIntegral p) * (fromIntegral(p - 1) * prev + x / (prev ^ (p - 1)))
- digit2 :: Int -> Bool
- digit2 n
- | n < 0 = digit2 (-n)
- | n == 0 = False
- | mod n 10 == 2 = True
- | otherwise = digit2 (div n 10)
- digitn :: Int -> Int -> Bool
- digitn m n
- | (n < 0 || m < 0) = digitn (abs m) (abs n)
- | m == 0 = False
- | mod m 10 == n = True
- | otherwise = digitn (div m 10) n
- -- ex 10
- findy :: Float -> Float
- findy x = findy_iter 256 x x*x
- findy_iter :: Int -> Float -> Float -> Float
- findy_iter 1 x y = x / y
- findy_iter i x y = findy_iter (div i 2) x ((fromIntegral i)/y+x*x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement