Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Lab2 where
- -- 1
- fun1 :: Int -> [Int]
- fun1 0 = []
- fun1 x = fun1 (x-1) ++ (x : [])
- fun2 :: Int -> [Int]
- fun2 0 = []
- fun2 x = fun2 (x-1) ++ (2*x-1 : [])
- fun3 :: Int -> [Int]
- fun3 0 = []
- fun3 x = fun3 (x-1) ++ (2*x : [])
- fun4 :: Int -> [Int]
- fun4 0 = []
- fun4 x = fun4 (x-1) ++ (x*x : [])
- fac :: (Integral a) => a -> a
- fac n = product [1..n]
- fun5 :: Int -> [Int]
- fun5 0 = []
- fun5 x = fun5 (x-1) ++ (fac(x) : [])
- fun6 :: Int -> [Int]
- fun6 0 = []
- fun6 x = fun6 (x-1) ++ (2 ^ (x - 1) : [])
- treug :: Int -> Int
- treug 1 = 1
- treug n = n + treug (n-1)
- fun7 :: Int -> [Int]
- fun7 0 = []
- fun7 x = fun7 (x-1) ++ (treug x : [])
- piram :: Int -> Int
- piram 1 = 1
- piram n = treug n + piram (n-1)
- fun8 :: Int -> [Int]
- fun8 0 = []
- fun8 x = fun8 (x-1) ++ (piram (x) : [])
- -- 2
- avg' :: [Double] -> Double -> Double -> Double
- avg' [] n s = s/n
- avg' (x:xs) n s = avg' xs (n+1) (s+x)
- avg :: [Double] -> Double
- avg x = avg' x 0 0
- removeItem :: Int -> [Int] -> [Int]
- removeItem n (x:xs) = if n == 1 then xs else x : removeItem (n-1) xs
- addElem :: [Int] -> [Int] -> [Int]
- addElem [] [] = []
- addElem (x:xs) [] = x:xs
- addElem [] (y:ys) = y:ys
- addElem (x:xs) (y:ys) = (x + y) : addElem xs ys
- swapEvenOdd :: [Int] -> [Int]
- swapEvenOdd [] = []
- swapEvenOdd [x] = [x]
- swapEvenOdd (x:y:xs) = if (odd(x + y)) then y :swapEvenOdd (x : xs) else x : swapEvenOdd (y : xs)
- twopow :: Integer -> Integer
- twopow n = if n == 1 then 2 else if even n then twopow (div n 2) * twopow (div n 2) else twopow (div n 2) * twopow (div n 2) * 2
- isOdd:: Int -> Bool
- isOdd x = mod x 2 /= 0
- removeOdd :: [Int] -> [Int]
- removeOdd [] = []
- removeOdd (x:xs) = if isOdd x then removeOdd xs else x : removeOdd xs
- removeEmpty :: [String] -> [String]
- removeEmpty [] = []
- removeEmpty (x:xs) = if x == "" then removeEmpty xs else x : removeEmpty xs
- countTrue :: [Bool] -> Int
- countTrue [] = 0
- countTrue (x:xs) = if x == True then 1 + countTrue xs else countTrue xs
- makePositive :: [Int] -> [Int]
- makePositive [] = []
- makePositive (x:xs) = if x < 0 then (-x) : makePositive xs else x : makePositive xs
- delete :: Char -> String -> String
- delete _ "" = ""
- delete x (y:ys) = if x == y then delete x ys else y : delete x ys
- substitute :: Char -> Char -> String -> String
- substitute _ _ "" = ""
- substitute x y (z:zs) = if x == z then y : substitute x y zs else z : substitute x y zs
Add Comment
Please, Sign In to add comment