Advertisement
O_Egor

Haskell лаба 0

Mar 12th, 2021 (edited)
1,455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Lab1 where
  2.  
  3. sort2 :: Int -> Int -> (Int, Int)
  4. sort2 a b = if a>b then (b, a) else (a, b)
  5.  
  6. bothTrue :: Bool -> Bool -> Bool
  7. bothTrue a b = if a then
  8.                      b
  9.                   else
  10.                      a
  11.  
  12. solve2 :: Double -> Double -> (Bool, Double)
  13. solve2 a b = if (a == 0 && b /= 0) then
  14.                (False, 0.0)
  15.             else if(a == 0 && b == 0) then
  16.                (True, 0)
  17.             else
  18.                (True, -b/a)
  19.  
  20. isParallel :: (Double, Double) -> (Double, Double) -> (Double, Double) -> (Double, Double) -> Bool
  21. isParallel (x1,y1) (x2, y2) (x3, y3) (x4, y4) = if ((y2 - y1) * (x4 - x3)) - ((y4 - y3) * (x2 - x1)) == 0 then
  22.                                                                                                             True
  23.                                                                                                           else
  24.                                                                                                             False
  25.  
  26. distance :: (Double, Double) -> (Double, Double) -> Double
  27. distance (x1, y1) (x2, y2) = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
  28.  
  29. isIncluded :: (Double, (Double, Double)) -> (Double, (Double, Double)) -> Bool
  30. isIncluded (r1, (x1, y1)) (r2, (x2, y2)) = if distance (x1, y1) (x2, y2) + r2 <= r1 then
  31.                                                                                  True
  32.                                                                               else
  33.                                                                                  False
  34.  
  35. isRectangel :: (Double, Double) -> (Double, Double) -> (Double, Double) -> Bool
  36. isRectangel (x1, y1) (x2, y2) (x3, y3) = if ((distance (x1, y1) (x2, y2))^2 == (distance (x1, y1) (x3, y3))^2 + (distance (x2, y2) (x3, y3))^2) ||
  37.                                             ((distance (x1, y1) (x3, y3))^2 == (distance (x1, y1) (x2, y2))^2 + (distance (x2, y2) (x3, y3))^2) ||
  38.                                             ((distance (x2, y2) (x3, y3))^2 == (distance (x1, y1) (x3, y3))^2 + (distance (x1, y1) (x2, y2))^2)
  39.                                           then
  40.                                              True
  41.                                           else
  42.                                              False
  43.  
  44. isSorted :: Int -> Int -> Int -> Bool
  45. isSorted a b c = if (a < b && b < c) || (a > b && b > c)
  46.                  then
  47.                      True
  48.                  else
  49.                      False
  50.  
  51. isTriangle :: (Double, Double) -> (Double, Double) -> (Double, Double) -> Bool
  52. isTriangle (x1, y1) (x2, y2) (x3, y3) = if(distance (x1, y1) (x2, y2) < (distance (x1, y1) (x3, y3) + distance (x2, y2) (x3, y3)) &&
  53.                                            distance (x1, y1) (x3, y3) < (distance (x1, y1) (x2, y2) + distance (x2, y2) (x3, y3)) &&
  54.                                            distance (x2, y2) (x3, y3) < (distance (x1, y1) (x2, y2) + distance (x1, y1) (x3, y3)))
  55.                                         then
  56.                                           True
  57.                                         else
  58.                                           False
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement