Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Gere Andor
- -- gaim2019
- -- 522/1
- -- Funk2
- import Data.Char
- --import Data.List.Split
- --------------------------------- 1.
- torol_szokoz :: String -> String
- torol_szokoz [] = []
- torol_szokoz (' ':xs) = torol_szokoz(xs)
- torol_szokoz (x:xs) = toLower x:torol_szokoz(xs)
- string_buffer :: Int -> String
- string_buffer 0 = []
- string_buffer n = " " ++ string_buffer (n-1)
- string_negyszog :: Int -> String -> [String]
- string_negyszog n s
- | length s>=n = take n s : string_negyszog n (drop n s)
- | length s>0 = [s ++ string_buffer (n-(length s))]
- | otherwise = []
- string_oszlop :: [String] -> String
- string_oszlop [] = []
- string_oszlop [[]] = []
- string_oszlop [x:xs] = [x] ++ string_oszlop [xs]
- --------------------------------- 2.
- oldPhone_lehet :: [Char] -> Bool
- oldPhone_lehet [] = True
- oldPhone_lehet (x:xs)
- | last (oldPhone [x]) == ('-',0) = False
- | otherwise = oldPhone_lehet xs
- oldPhone :: Num a => [Char] -> [(Char, a)]
- oldPhone [] = []
- oldPhone (x:xs)
- | isUpper x = ('*',1):(keres gombok (toLower x)):(oldPhone xs)
- | otherwise = (gomb,n):(oldPhone xs)
- where gombok=["1","aábc2","deéf3","ghií4","jkl5","mnoóöő6","pqrs7","tuúüűv8","wxyz9","+ 0",".,#","*"]
- (gomb,n) = keres gombok x
- keres :: Num a => [[Char]] -> Char -> (Char, a)
- keres [] _ = ('-',0)
- keres (x:xs) s
- | (keres2 x s 1) == ('0',0) = keres xs s
- | otherwise = (keres2 x s 1)
- keres2 :: Num t => [Char] -> Char -> t -> (Char, t)
- keres2 [] _ _ = ('0',0)
- keres2 (x:xs) s i
- | x == s && length xs == 0 = (x,i)
- | x == s = ((last xs),i)
- | otherwise = keres2 xs s (i+1)
- keres2 [x] _ i = (x,i)
- --------------------------------- 3.
- valos_preciz :: (Double, Integer)
- valos_preciz = until feltetel iteral (2,1)
- where
- feltetel (x, hatvany) = x/2 == 0
- iteral (x, hatvany) = (x*(1/2), hatvany+1)
- --------------------------------- 4.
- ln :: (Ord a, Floating a) => a -> a
- ln x
- | abs x >=1 = -ln2 (1/x)
- |otherwise = ln2 (1-x)
- where y = x-1
- ln2 :: (Floating a, Ord a) => a -> a
- ln2 y = -z
- where
- (z,_,_) = until felt iter (0,1,1)
- felt (z1,z2,_) = (abs (z1-z2)) < 1e-12
- iter (z1,z2,i) = (z1+((-l)**i/i),z1,i+1) where l = y-1
- --------------------------------- 5.
- cumul_op :: (a -> a -> a) -> [a] -> [a]
- cumul_op2 :: (a -> a -> a) -> [a] -> [a]
- cumul_op sz (x:xs) = x:cumul_op2 sz (x:xs)
- cumul_op2 sz (x:[]) = []
- cumul_op2 sz (x1:x2:xs) = x:cumul_op2 sz (x:xs) where x=(sz x1 x2)
- --------------------------------- 6.
- data BinFa a =
- Nodus (BinFa a) a (BinFa a)
- | Level
- deriving Show
- beszur :: Ord a => BinFa a -> a -> BinFa a
- beszur Level x = Nodus Level x Level
- beszur (Nodus bal a jobb) x
- | a == x = Nodus bal a jobb
- | a < x = Nodus bal a (beszur jobb x)
- | a > x = Nodus (beszur bal x) a jobb
- listabol :: Ord a => [a] -> BinFa a
- listabol = foldl beszur Level
- torol :: Ord a => BinFa a -> a -> Maybe (BinFa a)
- torol Level x = Nothing
- torol (Nodus bal a jobb) x = case compare x a of
- GT -> case torol jobb x of
- Nothing -> Nothing
- Just binfa -> Just (Nodus bal a binfa)
- LT -> case torol bal x of
- Nothing -> Nothing
- Just binfa -> Just (Nodus binfa a jobb)
- EQ -> torol2 (Nodus bal a jobb) x
- torol2 :: Ord a => BinFa a -> a -> Maybe (BinFa a)
- torol2 (Nodus Level a Level) x = Just Level
- torol2 (Nodus Level a j) _ = Just j
- torol2 (Nodus b a Level) _ = Just b
- torol2 (Nodus b a j) _ = Just (Nodus b uj jj)
- where uj = mini j
- Just jj = torol j uj
- mini (Nodus Level uj _) = uj
- mini (Nodus b _ _) = mini b
- --------------------------------- 7.
- data COMPLEX = Comp {a :: Float, b :: Float}
- instance Show COMPLEX where
- show (Comp a b)
- | b==0 = show a
- | b<0 = show a ++ show b ++ "i"
- | otherwise = show a ++ "+" ++ show b ++ "i"
- instance Num COMPLEX where
- (Comp a b) + (Comp c d) = (Comp (a+c) (b+d))
- (Comp a b) - (Comp c d) = (Comp (a-c) (b-d))
- (Comp a b) * (Comp c d) = (Comp (a*c - b*d) (b*d + a*d))
- abs (Comp a b) = Comp (sqrt (a*a + b*b)) 0
- instance Fractional COMPLEX where
- (Comp a b) / (Comp c d) = (Comp ((a*c + b*d) / (c*c + d*d)) ((b*c - a*d) / (c*c + d*d)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement