Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Aufgabe 1
- --1
- quadratic :: ( Int , Int , Int ) -> Int -> Int
- quadratic (a,b,c) x = a*(x*x)+b*x+c --wende gleichung an
- --2
- square :: Int -> Int
- square x
- |x==0 =0
- |x<0 =square(-x)
- |otherwise =x*x --quadriere
- --3 a
- sumList :: [Int] -> Int
- sumList [] = 0
- sumList (x:xs) = x + sumList xs --rekursiv erstes element addieren
- --3 b
- foldList :: ( Double -> Double -> Double ) -> [ Double ] -> Double
- foldList (op) [] = 0
- foldList (op) (x:xs) = x + foldList (op) xs
- --3 c
- mapList :: ( Int -> Int ) -> [ Int ] -> [ Int ]
- mapList (func) [] = []
- mapList (func) (x:xs) = [func x] ++ mapList (func) xs --an Liste muss ein Teil einer Liste dran damit die Liste länger wird und man eine Liste hat
- --4
- tableInt :: ( Int -> Int ) -> [ Int ] -> String
- tableInt (func) [] = ""
- tableInt (func) (x:xs) = show(x) ++":"++ show(func x) ++ "\n" ++ tableInt(func) xs --gib aus+gib mit fkt aus
- --Aufgabe 2
- --1
- containsList :: [ Int ] -> Int -> Bool
- containsList (x:xs) y
- |x==y = True --ist element drin
- |xs==[] = False -- liste zuende
- |otherwise = containsList (xs) y
- --2
- import Data.Char ( toLower )
- countList :: [ Char ] -> Char -> Int
- countList [] c = 0
- countList (x:xs) c
- |toLower x == c =1+countList (xs) c --counter wird immer hochgezählt, sodass wert am ende 1+1+1+1+1+1+...==X ausgibt
- |otherwise = countList (xs) c
- --3
- bubbleSortList :: [ Int ] -> [ Int ]
- bubbleSortList [] = []
- bubbleSortList (x:xs) = stufe (foldl naechster (x,[]) xs)
- where
- naechster(y,t) x = (min x y, max x y :t)
- stufe(x,t) = x : bubbleSortList t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement