Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sumMy :: (Num a) => [a] -> a
- sumMy [] = 0
- sumMy (x:xs) = x + sumMy xs
- headMy :: [a] -> a
- headMy (x:_) = x
- tailMy :: [a] -> [a]
- tailMy (_:xs) = xs
- -- reverseMy :: [a] -> [a]
- reverseMy [] = []
- reverseMy list = last list : reverseMy (init list)
- reverseMy1 :: [a] -> [a]
- reverseMy1 [] = []
- reverseMy1 (x:xs) = reverseMy1 xs ++ [x]
- len :: [a] -> Int
- len [] = 0
- len (_:xs) = 1 + len xs
- count :: (Ord a) => a -> [a] -> Int
- count _ [] = 0
- count num (x:xs)
- | num == x = 1 + count num xs
- | otherwise = count num xs
- triangle :: Float -> Float -> Float -> [Float]
- triangle a b c
- | a>0 && b>0 && c>0 && a<b+c && b<a+c && c<a+b = [per, s]
- | otherwise = [-1, -1]
- where
- per = a + b + c
- p = per/2
- s = sqrt (p*(p-a)*(p-b)*(p-c))
- rect :: Float -> Float -> (Float, Float, [Char])
- rect a b
- | a <= 0 || b <= 0 = (-1, -1, "invalid")
- | a == b = (p, s, "square")
- | otherwise = (p, s, "rectangle")
- where
- p = 2*(a+b)
- s = a*b
- doubleNum x = 2*x
- mapMy :: (a->b) -> [a] -> [b]
- mapMy _ [] = []
- mapMy f (x:xs) = f x : mapMy f xs
- qSort :: (Ord a) => [a] -> [a]
- qSort [] = []
- qSort (x:xs) = qSort less ++ [x] ++ qSort more
- where
- less = (filter (<x) xs)
- more = (filter (>=x) xs)
- qSort2 :: (Ord a) => [a] -> [a]
- qSort2 [] = []
- qSort2 (x:xs) = qSort2 [y | y <- xs, y < x] ++ [x] ++ qSort2 [y | y <- xs, y >= x]
- primes :: [Int]
- primes = filterPrime [2..]
- where filterPrime (p:xs) =
- p : filterPrime [x | x <- xs, x `mod` p /= 0]
- getOperation :: Int -> (Int->Int->Int)
- getOperation 1 = \x y -> x + y
- getOperation 2 = \x y -> x - y
- getOperation 3 = \x y -> x * y
- getOperation 4 = \x y -> x `div` y
Add Comment
Please, Sign In to add comment