SHOW:
|
|
- or go back to the newest paste.
| 1 | module Lab1 where | |
| 2 | ||
| 3 | - | square :: Int->Int |
| 3 | + | square :: Int->Int |
| 4 | square x = x*x | |
| 5 | ||
| 6 | prod :: Int->Int->Int | |
| 7 | prod x y = x*y | |
| 8 | ||
| 9 | - | z = if True then 1 else 2 |
| 9 | + | |
| 10 | ispositive x = if x>0 then True else False | |
| 11 | ||
| 12 | singnum :: Int->Int | |
| 13 | singnum x = if x>0 then 1 else if x<0 then -1 else 0 | |
| 14 | ||
| 15 | max3 :: Int->Int->Int->Int | |
| 16 | max3 a b c = if a>b && a>c then a else if b>a && b>c then b else c | |
| 17 | ||
| 18 | sort2 :: Int->Int->(Int,Int) | |
| 19 | sort2 a b = if a > b then (b, a) else (a, b) | |
| 20 | ||
| 21 | bothTrue :: Bool->Bool->Bool | |
| 22 | bothTrue a b = if a == True then if b == True then True else False else False | |
| 23 | - | bothTrue :: ne ispolzyite logi4eskie operatsii |
| 23 | + | |
| 24 | solved :: Double->Double->(Bool,Double) | |
| 25 | - | solvel :: Double->Double->(Bool,Double) |
| 25 | + | solved a b = if ( a == 0 && b /= 0) then (False, 0) else if (a == 0 && b == 0) then (True, 0) else (True, -b/a) |
| 26 | - | true esli resh syshestvyet false v protivnom sluchae |
| 26 | + | |
| 27 | - | pri etom vtoroi element ravent znach kornya libo nylu |
| 27 | + | isParallel :: ((Double, Double), (Double, Double))->((Double, Double), (Double, Double))->Bool |
| 28 | isParallel (x1, y1) (x2, y2) = if (fst y1 - fst x1) * (snd y2 - snd x2) - ( fst y2 - fst x2) * (fst y1 - snd x1) == 0 then True else False | |
| 29 | - | isParallel :: Double->Double->Double->Double->Bool |
| 29 | + | |
| 30 | - | true esli dva otrezka konci kotorih zadautsya v argumentah funkcii parallelni false esli net |
| 30 | + | isIncluded :: (Double, (Double, Double))->(Double, (Double, Double))->Bool |
| 31 | isIncluded (r1, (x1, y1)) (r2, (x2, y2)) = if sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2) + r2 <= r1 then True else False | |
| 32 | - | isIncluded :: Double->Double->Double->Double->Double->Double->Bool |
| 32 | + | |
| 33 | - | true esli vtoraya vnytri pervoi |
| 33 | + | scalar :: (Double, Double)->(Double, Double)->Bool |
| 34 | scalar (x1, y1) (x2, y2) = if x1 * x2 + y1 * y2 == 0 then True else False | |
| 35 | - | isRectangular :: Double->Double->Double->Double->Double->Double->Bool |
| 35 | + | isRectangular :: (Double, Double)->(Double, Double)->(Double,Double)->Bool |
| 36 | - | true esli pryamoygolniy |
| 36 | + | isRectangular (x1, y1) (x2, y2) (x3, y3) = if scalar ((x2 - x1), (y2 - y1)) ((x3 - x1), (y3 - y1)) == True || scalar ((x1 - x2), (y1 - y2)) ((x3 - x2), (y3 - y2)) == True || scalar ((x1 - x3), (y1 - y3)) ((x2 - x3), (y2 - y3)) == True then True else False |
| 37 | ||
| 38 | - | isTriangle :: Double->Double->Double->Double->Double->Double->Bool |
| 38 | + | isTriangle :: Double->Double->Double->Bool |
| 39 | - | true esli treugolnik |
| 39 | + | isTriangle a b c = if a + b > c && b + c > a && a + c > b then True else False |
| 40 | ||
| 41 | isSorted :: Int->Int->Int->Bool | |
| 42 | - | true esli sorted |
| 42 | + | isSorted a b c = if((a < b && b < c) || (a > b && b > c)) then True else False |